1

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

hd.
  • 17,596
  • 46
  • 115
  • 165

3 Answers3

2

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!

Stu
  • 4,160
  • 24
  • 43
1

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,
),
rodrigovr
  • 454
  • 2
  • 7
  • This works great, but it looks like the content within the tab loses its styling, for example, links are no longer blue. – Pat Needham Dec 17 '13 at 16:40
  • @Pat I guess your problem is CSS-related. The html content of each tab will inherit a lot of styling from its parent. Try some browser-level debbuger (F12) – rodrigovr Dec 27 '13 at 11:15
0

below is ok.

'Tab1'=> array('content' => $this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$vulnerdataProvider,
    'itemView'=>'_latest_vulner' ), true)
Ben
  • 1