CTabView: Allow different data for each view

CTabView can render different views in tabs. But every view is supplied with the same set of data provided in viewData:


$this->widget('CTabView',array(

    'viewData'=>array (

        'x' => $x,

        'y'=>$y,

    ),


    'tabs'=>array(


        'tab1' => array(

           'title' => 'Demo 1 ',

           'view' => 'demo1',

        ),


        'tab2' => array(

           'title' => 'Demo 2',

           'view' => 'demo2',

        ),


    ),

));

Each view is rendered with local variables $x and $y. As long as the views don’t use the same variables for different things this may not be a big problem. But if they do it would be good if we could supply view variables like this (doesn’t break bc, if the above is still accepted):


$this->widget('CTabView',array(

    'tabs'=>array(


        'tab1' => array(

           'title' => 'Demo 1 ',

           'view' => array('demo1', 'x'=>$x),

        ),


        'tab2' => array(

           'title' => 'Demo 2',

           'view' => array('demo2', 'y'=>$y)

        ),


    ),

));

You can override CTabView to adapt this functionality. If you see the code you will find that in not too hard to do what you want.

Of course, it will be so usefull if this is implemented in the core…

Sure. But as it requires only a little change it would be nice to have it in Yii. I see that it’s easier to implement if we would change the syntax like this:


$this->widget('CTabView',array(

    'tabs'=>array(


        'tab1' => array(

           'title' => 'Demo 1 ',

           'view' => array('demo1', array(

               'x'=>$x

           )),

        ),



Required change in CTabView:196 :


            if(isset($tab['content']))

                echo $tab['content'];

            else if(isset($tab['view']) { 

                if(is_array($tab['view']))

                    $this->getController()->renderPartial($tab['view'][0],$tab['view'][1]);

                else

                    $this->getController()->renderPartial($tab['view'],$this->viewData);

            }