[Solved] Registerscript Error

Hi to everyone,

I’ve this code:


Yii::app()->clientScript->registerScript('customFnc', "

    $.fn.toggleSpinner = function() {

      var spinner = '<div class=\"spinner-content\"><i class=\"icon-spinner icon-spin icon-3x\"></i></div>',

          _this = $(this),

          spinnerContent = $this.find('.spinner-content'),

          isSpinning = spinnerContent.size();

      if(isSpinning)

        spinnerContent.remove();

      else

        return _this.prepend(spinner);

    }

  ", CClientScript::POS_READY);

when I run my application this error occurs:

Object of class could not be converted to string

What’s the problem?

Debug finds the error on the last line of the above code, even if I remove CClientScript::POS_READY.

Are you getting an PHP or HTML / JS error ?

Also what is the element "i", I guess that should be img - i.e. in your code you have <i class=…>

Hi Maurizio and thank you for your reply,

I’m getting an PHP error

That ‘i’ element belongs to the spinner of this page

Strange… is that the whole error?

I mean after "Object of class" it should say the name of the class.

The class name is SiteController, sorry.

I’m trying to add javascript code on the main.php layout

It’s IMO easier to use a a heredoc block:




<?php

        $script = <<<EOD




   	// write pure javascript here without the need to escape




EOD;


Yii::app()->clientScript->registerScript('customFnc', $script, CClientScript::POS_READY);?>

I agree it’s easier :)

by the way the problem persists :confused:

The problem was on the 5th row:

I forgot to replace $this with _this

Thanks for your support :)

D’oh!

Errors like that are extremely easy to miss :)

You said it :D