Reputation: 18346
How can I pass output of a widget as content in CJuiTabs in Yii?
Here the code I tried and get error:
$this->widget('zii.widgets.jui.CJuiTabs',array(
'tabs'=>array(
'Tab1'=> array('content' => $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$vulnerdataProvider,
'itemView'=>'_latest_vulner' )),
'id' => 'tab1'),
'tab2'=>array('content'=>'Content for tab 2', 'id'=>'tab2'),
),
// additional javascript options for the tabs plugin
'options'=>array(
'collapsible'=>true,
),
));
it gives this error:
Object of class CListView could not be converted to string
Edited: As well as Stu's answer I found this : http://yiibook.blogspot.nl/2012/09/handle-cjuitabs-in-yii.html
Upvotes: 1
Views: 1944
Reputation: 1
below is ok.
'Tab1'=> array('content' => $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$vulnerdataProvider,
'itemView'=>'_latest_vulner' ), true)
Upvotes: 0
Reputation: 454
You can set the second parameter of $this->widget() to true, so the method will return the content of the widget istead of echoing it.
$this->widget('zii.widgets.jui.CJuiTabs',array(
'tabs'=>array(
'Tab1'=> array('content' => $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$vulnerdataProvider,
'itemView'=>'_latest_vulner' ), true),
'id' => 'tab1'),
'tab2'=>array('content'=>'Content for tab 2', 'id'=>'tab2'),
),
// additional javascript options for the tabs plugin
'options'=>array(
'collapsible'=>true,
),
Upvotes: 1
Reputation: 4150
Yeah, content expects a string and the widget doesn't return a string. I found this blog piece here: http://mrhandscode.blogspot.com/2012/03/insert-widget-to-another-widget-in-yii.html
The owner found a pretty innovative way round this issue, using output buffering to collect the output of the one widget and then inserting that into the second.
You might be able to achieve it with something like this:
ob_start();
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$vulnerdataProvider,
'itemView'=>'_latest_vulner'
));
$tab1Content=ob_get_contents();
ob_end_clean();
$this->widget('zii.widgets.jui.CJuiTabs',array(
'tabs'=>array(
'Tab1'=> array('content' => $tab1Content,'id' => 'tab1'),
'tab2'=>array('content'=>'Content for tab 2', 'id'=>'tab2'),
),
// additional javascript options for the tabs plugin
'options'=>array(
'collapsible'=>true,
),
));
I've not tested, and may need tinkering!
Upvotes: 2