Yii 1.1: First Yii App: CTabView

1 follower

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

(thanks to horizons) edit line 13 to

<?php echo CHtml::link($model->id,array('user/show','id'=>$model->id)); ?>

Total 1 comment

#9997 report it
Hestimz at 2012/09/27 06:50pm
huh?

really, what is this wiki all about?!

Leave a comment

Please to leave your comment.

Write new article
  • Written by: meanpenguin
  • Updated by: Yang He
  • Category: Tutorials
  • Yii Version: 1.1
  • Votes: -2
  • Viewed: 17,046 times
  • Created on: Feb 8, 2009
  • Last updated: Jun 29, 2012