Rendering Widgets in a CHtml-Script

Hi there!

I am using an extjs panel nested into one of my yii-views.

Inside of this extjs-panel I tried to include the UserLogin component which is also used in the official examples.

But all I get is this message:

Quote

Property "SiteController.widget" is not defined.

SiteController is my Controller  ;)

Here is a sourcecode snippet of the view:

Quote

<?php echo CHtml::script("

Ext.onReady(function(){

    var p = new Ext.Panel({

        title: 'My Panel',

        collapsible:true,

        renderTo: 'content',

        width:400,

        html:    <?php $this->widget('UserLogin',array('visible'=>Yii::app()->user->isGuest)); ?>

    });

});

  "); ?>

Using

Quote

$this->widget('UserLogin',array('visible'=>Yii::app()->user->isGuest)); ?>

in the view works just fine… But I am trying to embedd it in the ext-panel as i said before…

Btw.: Using ext for display purposes works fine with yii too, my problem is just the rendering of yii-widgets inside of the chtml-script tags…

Thanks in advance!

ezt

I couldn't understand this usage. What is $this? How does this widget() call get executed?

CHtml::script expects a string argument, but you are trying to use $this->widget within the argument which shouldn't work, because $this->widget returns the widget object instance instead of a string output.

So you'll probably need to find a way to capture the widget string output as a string (maybe using output buffering?), then use the output buffered string within the argument instead?

Edit: Just found an example of output buffering in Yii here, you can probably use this:

http://www.yiiframew…26.html#msg3826

Example code:



    <?php 


$this->beginClip('userlogin');


$this->widget('UserLogin',array('visible'=>Yii::app()->user->isGuest));


$this->endClip();


$userlogin = $this->clips['userlogin'];


$script = <<<EOD





    Ext.onReady(function(){


        var p = new Ext.Panel({


            title: 'My Panel',


            collapsible:true,


            renderTo: 'content',


            width:400,


            html: '$userlogin'                      





        });


    });





EOD;








echo CHtml::script($script); ?> 

Hi WilsonC!

Thanks a lot for your advice!

Best regards

ezt

P.S.:

Quote

            html: $userlogin   

without the double quotes worked for me!