* @link http://www.yiiframework.com/ * @copyright 2008-2013 Yii Software LLC * @license http://www.yiiframework.com/license/ */ /** * CTabView displays contents in multiple tabs. * * At any time, only one tab is visible. Users can click on the tab header * to switch to see another tab of content. * * JavaScript is used to control the tab switching. If JavaScript is disabled, * CTabView still manages to display the content in a semantically appropriate way. * * To specify contents and their tab structure, configure the {@link tabs} property. * The {@link tabs} property takes an array with tab ID being mapped tab definition. * Each tab definition is an array of the following structure: *
* $this->widget('CTabView', array(
* 'tabs'=>array(
* 'tab1'=>array(
* 'title'=>'tab 1 title',
* 'view'=>'view1',
* 'data'=>array('model'=>$model),
* ),
* 'tab2'=>array(
* 'title'=>'tab 2 title',
* 'url'=>'http://www.yiiframework.com/',
* ),
* ),
* ));
*
*
* By default, the first tab will be activated. To activate a different tab
* when the page is initially loaded, set {@link activeTab} to be the ID of the desired tab.
*
* @author Qiang Xue * array( * 'tab1'=>array( * 'title'=>'tab 1 title', * 'view'=>'view1', * ), * 'tab2'=>array( * 'title'=>'tab 2 title', * 'url'=>'http://www.yiiframework.com/', * ), * ) **/ public $tabs=array(); /** * Runs the widget. */ public function run() { foreach($this->tabs as $id=>$tab) if(isset($tab['visible']) && $tab['visible']==false) unset($this->tabs[$id]); if(empty($this->tabs)) return; if($this->activeTab===null || !isset($this->tabs[$this->activeTab])) { reset($this->tabs); list($this->activeTab, )=each($this->tabs); } $htmlOptions=$this->htmlOptions; if(isset($this->htmlOptions['id'])) $this->id=$this->htmlOptions['id']; else $htmlOptions['id']=$this->id; if(!isset($htmlOptions['class'])) $htmlOptions['class']=self::CSS_CLASS; $this->registerClientScript(); echo CHtml::openTag('div',$htmlOptions)."\n"; $this->renderHeader(); $this->renderBody(); echo CHtml::closeTag('div'); } /** * Registers the needed CSS and JavaScript. */ public function registerClientScript() { $cs=Yii::app()->getClientScript(); $cs->registerCoreScript('yiitab'); $id=$this->getId(); $cs->registerScript('Yii.CTabView#'.$id,"jQuery(\"#{$id}\").yiitab();"); if($this->cssFile!==false) self::registerCssFile($this->cssFile); } /** * Registers the needed CSS file. * @param string $url the CSS URL. If null, a default CSS URL will be used. */ public static function registerCssFile($url=null) { $cs=Yii::app()->getClientScript(); if($url===null) $url=$cs->getCoreScriptUrl().'/yiitab/jquery.yiitab.css'; $cs->registerCssFile($url,'screen'); } /** * Renders the header part. */ protected function renderHeader() { echo "