0

Iam using CJUI tabs for my tab display. I would like to implement a condition based display of tabs based on the user logged in. I have 2 user admin and customer. If customer is logged in I need to hide a tab. Since customer has no permission to acess those data.Iam creating tabs using this method :-

  $usertype = Yii::app()->user->getstate('usertype'); // to get the user type
    if ($usertype == 'customer') {
    // hide $tab4
    } else {
    // show $tab4
    }
  $this->widget('zii.widgets.jui.CTab', array(
        'tabs' => array(
            'Summary' => $this->renderPartial('summary', null, true),
            'Portfolio' => $this->renderPartial('portfolio', null, true),
            'Contact' => $this->renderPartial('contact', null, true),
            $tab4 => $this->renderPartial('team', null, true),
        ),

How can I show/hide tab4 based on the condition ?

anu
  • 458
  • 2
  • 13
  • 36

2 Answers2

1

You can do it dynamically taking the tabs in an array an assigning that array accordingly to the tab as shown below Giving a simple example of dynamic content of tab

<?php
 //Your code to construct the array based on condition using any loop constructs
 $tabarray["$TabName"]= $this->renderPartial('$ViewName', null, true);
}
?>

<?php
$this->widget('zii.widgets.jui.CJuiTabs',array(
    'tabs'=>$tabarray,
    // additional javascript options for the accordion plugin
    'options' => array(
        'collapsible' => true,       
    ),
   'id'=>'MyTab-Menu1'
));
?>
Ninad
  • 1,871
  • 3
  • 15
  • 23
1

Only add the tabs that you want to display in the array

$usertype = Yii::app()->user->getstate('usertype'); // to get the user type

$tabList = array(); // Tab list to show
$tabList['Summary']   = $this->renderPartial('summary', null, true);
$tabList['Portfolio'] = $this->renderPartial('portfolio', null, true);
$tabList['Contact']   = $this->renderPartial('contact', null, true);
$tabList['Summary']   = $this->renderPartial('summary', null, true);

if ($usertype == 'admin') { // Only 'admin' show tab 'team'
    $tabList['team'] = $this->renderPartial('team', null, true);
}

$this->widget('zii.widgets.jui.CTab', array(
               'tabs' => $tabList,
),
Daniel Vaquero
  • 1,315
  • 1
  • 8
  • 13