0

i've been using Yii framework for some time now, and i've been really having a good time especially with these widgets that makes the development easier. I'm using Yii bootsrap for my extensions..but i'm having a little trouble understanding how each widget works.

My question is how do i display the widget say a TbDetailView inside a tab? i basically want to display contents in tab forms..however some of them are in table forms...some are in lists, detailviews etc.

I have this widget :

$this->widget('bootstrap.widgets.TbDetailView',array(
        'data'=>$model,
        'attributes'=>$attributes1,
        )); 

that i want to put inside a tab

$this->widget('bootstrap.widgets.TbWizard', array(
    'tabs' => $tabs,
    'type' => 'tabs', // 'tabs' or 'pills'
    'options' => array(
        'onTabShow' => 'js:function(tab, navigation, index) {
            var $total = navigation.find("li").length;
            var $current = index+1;
            var $percent = ($current/$total) * 100;
            $("#wizard-bar > .bar").css({width:$percent+"%"});
        }',
    ),

and my $tabs array is declared like this :

$tabs = array('studydetails' => 
array(
'id'=>'f1study-create-studydetails', 
'label' => 'Study Details', 
'content' =>//what do i put here?),
...
...);

when i store the widget inside a variable like a $table = $this->widget('boots....); and use the $table variable for the 'content' parameter i get an error message like: Object of class TbDetailView could not be converted to string

I don't quite seem to understand how this works...i need help..Thanks :)

2 Answers 2

2

You can use a renderPartial() directly in your content, like this:

'content'=>$this->renderPartial('_tabpage1', [] ,true),

Now yii will try to render a file called '_tabpage1.php' which should be in the same folder as the view rendering the wizard. You must return what renderPartial generates instead of rendering it directly, thus set the 3rd parameter to true.

Sign up to request clarification or add additional context in comments.

1 Comment

that's right! why didn't i think of this...haha..thanks!:) works wonders
2

The third parameter that the widget() function takes is used to capture output into a variable like you are trying to do.

from the docs:

public mixed widget(string $className, array $properties=array ( ), boolean $captureOutput=false)

$this->widget('class', array(options), true)

Right now you are capturing the object itself in the variable trying to echo out an object. Echo only works for things that can be cast to a string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.