Wednesday, January 15, 2014

CTabView with partial view in each tab (Yii)

Suppose using Yii framework and we want to add a tab control in which each tab shows a partial view, the following codes shows how this can be done:

<?php
$nc_view=$this->renderPartial('_viewNodeConfig', array('project'=>$model), $return=true);
$user_view=$this->renderPartial('_viewUser', array('project'=>$model), $return=true);
$sim_view=$this->renderPartial('_viewSimulation', array('project'=>$model), $return=true);

$this->widget('CTabView',array(
    'activeTab'=>'tab2',
    'tabs'=>array(
        'tab1'=>array(
            'title'=>'Users',
            'content'=>$user_view,
        ),
        'tab2'=>array(
            'title'=>'Node Types',
            'content'=>$nc_view,
        ),
        'tab3'=>array(
            'title'=>'Simulations',
            'content'=>$sim_view,
        )
    ),
    'htmlOptions'=>array(
        //'style'=>'width:500px;'
    )
));
?>
In the above codes, the _viewNodeConfig.php is a partial view which looks like the following:
<?php 
$node_configs=new CActiveDataProvider('NodeConfig', 
    array(
     'criteria'=>array( 
      'condition'=>'audit_project_id=:projectId', 
      'params'=>array(':projectId'=>$project->id),
     ),
     'pagination'=>array( 
      'pageSize'=>4,
     ), 
    )
   );
   
$this->widget('zii.widgets.CListView', array(
 'dataProvider'=>$node_configs,
 'viewData'=>array('project'=>$project),
 'itemView'=>'/nodeConfig/_view',
)); 
?>

No comments:

Post a Comment