Beginner: CTabView

You are viewing revision #5 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#6) »

  1. Change your ...\protected\views\site\index.php to the following
  2. Load the home page for your First Yii application and you should see 2 tabs.

Once you are completed with the "Creating First Yii Application", the following can be done.

Change your ...\protected\views\site\index.php to the following

<?php $this->pageTitle=Yii::app()->name; ?>

<h1>
	Welcome, <?php echo Yii::app()->user->name; ?>!
</h1>

<?php  

   // ON TAB 1: THIS IS STATIC CONTENT THAT IS TO BE DISPLAYED
   $Content1 = 'This is content that is to be displayed on tab 1';
   
   // ON TAB 2: DISPLAY THE USER LIST WHICH IS THE SAME AS THE OUTPUT OF
   // index.php?r=user/list

   // GET THE DATA FOR USE BY THE TAB PAGE VIEW WHEN GENERATING THE OUTPUT
   $userList=User::model()->findAll(); // ??? should this be moved into the site controller???

   // DATA ATTACHED TO THE $viewData IS PASSED IN TO THE CTabView 
   // WHERE THE VIEW FOR THE TAB PAGE CAN USE IT TO GENERATE THEIR OUTPUT
   $viewData = array
               (
                  'userList'=>$userList
               );
   
   // ** I GOT STUCK HERE FOR A WHILE...
   // FOR TAB2, VIEW SPECIFICATION, MUST HAVE LEADING "/" OTHERWISE
   // Yii WILL LOOK FOR THE VIEW FILE UNDER THE site INSTEAD OF user
   $Tabs     = array
               (
                  'tab1'=>array('title'=>'Tab 1 Title','content'=>$Content1),
                  'tab2'=>array('title'=>'Tab 2 Title','view'=>'/user/list'),
               );
                        
   // THERE ARE EXAMPLE CODE WHERE THE Widget() CAN INCORPORATE 
   // THE $viewData and $Tabs VALUES DIRECTLY BUT THIS IS EASIER TO UNDERSTAND....
   $this->widget('CTabView', array('tabs'=>$Tabs, 'viewData'=>$viewData));
                 
?>

Load the home page for your First Yii application and you should see 2 tabs.

You will notice that on tab 2, the 'New User' and the 'Manage User' links don't work.

To fix that, edit the ...\protected\views\user\list.php file. edit lines 4 and 5. Add 'user/' in front of 'create' and 'admin'.

[<?php echo CHtml::link('New User',array('user/create')); ?>]
[<?php echo CHtml::link('Manage User',array('user/admin')); ?>]
0 2
1 follower
Viewed: 28 311 times
Version: Unknown (update)
Category: Tutorials
Tags:
Written by: meanpenguin
Last updated by: Yang He
Created on: Feb 9, 2009
Last updated: 12 years ago
Update Article

Revisions

View all history