cerbero
(22cerbero22)
January 15, 2013, 2:30pm
1
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 .
mdomba
(Maurizio Domba Cerin)
January 15, 2013, 2:41pm
2
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=…>
cerbero
(22cerbero22)
January 15, 2013, 2:47pm
3
Hi Maurizio and thank you for your reply,
I’m getting an PHP error
That ‘i’ element belongs to the spinner of this page
mdomba
(Maurizio Domba Cerin)
January 15, 2013, 2:55pm
4
Strange… is that the whole error?
I mean after "Object of class" it should say the name of the class.
cerbero
(22cerbero22)
January 15, 2013, 3:03pm
5
The class name is SiteController, sorry.
I’m trying to add javascript code on the main.php layout
jacmoe
(Jacob Moena)
January 15, 2013, 3:03pm
6
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);?>
cerbero
(22cerbero22)
January 15, 2013, 3:12pm
7
I agree it’s easier
by the way the problem persists
cerbero
(22cerbero22)
January 15, 2013, 3:29pm
8
The problem was on the 5th row:
I forgot to replace $this with _this
Thanks for your support
jacmoe
(Jacob Moena)
January 15, 2013, 3:33pm
9
D’oh!
Errors like that are extremely easy to miss