Yii 1.1: Advanced CTabView using CClipWidget

2 followers

Here is a way to dynamically extend tabs based on clips.
Probably even more complex things could be done.

<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'My tab 1')); ?>
    My tab 1 ...
<?php $this->endWidget(); ?>
 
<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'My tab 2')); ?>
    My tab 2 ...
<?php $this->endWidget(); ?>
 
<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'My tab 3')); ?>
    My tab 3 ...
<?php $this->endWidget(); ?>
 
<?php
$tabParameters = array();
foreach($this->clips as $key=>$clip)
    $tabParameters['tab'.(count($tabParameters)+1)] = array('title'=>$key, 'content'=>$clip);
?>
 
<?php $this->widget('system.web.widgets.CTabView', array('tabs'=>$tabParameters)); ?>

Links ΒΆ

Russian Version

Total 1 comment

#2439 report it
Sheldmandu at 2011/01/02 08:17am
Another way of doing this...

I use tabs extensively in the admin module and was looking for something like this... Initially I didn't know about CClipWidget and hence implemented this using ob_start() and ob_get_clean(), but this is a much better solution. The only thing I would say is that these days you should be using CJuiTabs. If you have some tabs that use ajax you may also consider setting the tabs for the CJuiTabs manually rather than using a foreach loop as it's more trouble than it's worth.

Leave a comment

Please to leave your comment.

Write new article
  • Written by: krillzip
  • Updated by: Yang He
  • Category: Tutorials
  • Yii Version: 1.1
  • Votes: +2
  • Viewed: 10,239 times
  • Created on: Feb 11, 2009
  • Last updated: Jun 29, 2012