我使用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?
答案 0 :(得分: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'
));
?>
答案 1 :(得分: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,
),