0

我正在使用 CJUI 选项卡来显示我的选项卡。我想根据登录的用户实现基于条件的选项卡显示。我有 2 个用户管理员和客户。如果客户已登录,我需要隐藏一个选项卡。由于客户无权访问这些数据。我正在使用此方法创建选项卡:-

  $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),
        ),

如何根据条件显示/隐藏 tab4?

4

2 回答 2

1

您可以动态地获取数组中的选项卡,并将该​​数组相应地分配给选项卡,如下所示给出选项卡动态内容的简单示例

<?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'
));
?>
于 2013-07-18T05:32:48.313 回答
1

仅添加要在数组中显示的选项卡

$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,
),
于 2013-07-18T07:05:16.750 回答