2013-07-18 31 views
0

Iam使用CJUI選項卡顯示我的選項卡。我想實現基於條件的顯示基於用戶登錄的選項卡。我有2個用戶管理員和客戶。如果客戶登錄,我需要隱藏一個標籤。由於客戶沒有權限訪問這些數據。Iam使用此方法創建選項卡: -根據Yii中的條件顯示CJUI選項卡

$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?

回答

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, 
), 
+0

謝謝。這一次救了我的工作 – anu

+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' 
)); 
?> 
+0

感謝您的回答。但是,我怎麼能添加多個選項卡到這個$ tabarray – anu

+0

使用for循環或任何相關的構造!或者你可以像@Daniel Vaquero所示的那樣做 – Ninad

+0

謝謝。我有你的兩個概念,這對我很有幫助 – anu