CTabView, redirect to previous active tab after update

Hi all,

I am having difficult redirecting back to the tab that was active before update.

I have these tabs in [color="#FF0000"]MdGenera[/color]l view/form: |General|Training|Education|Experience

On Update mode when you click on Training tab you can view Trainings attended/add new or update existing Trainining attended by Md.If you choose to update you will be taken to [color="#FF0000"]MdTraining contoller[/color] below.

Is there a way I can redirect back to Training tab in [color="#FF0000"]MdGeneral[/color] after update?




     

	public function actionUpdate($id)

	{

		$model=$this->loadModel($id);

  

		if(isset($_POST['MdTraining']))

		{

            $model->attributes=$_POST['MdTraining'];

			if($model->save())

			

             //move back to Training tab after save

              $activeTab='Training'; // id of the tab with your form

             else

              $activeTab='General'; // id of first tab


            	$this->redirect(array('MdGeneral/update','id'=>$model->MDID));

        }


		$this->render('update',array(

		    'model'=>$model,

		));

	}



Part of MdGeneral CTabView look like this




<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'General')); ?>

<table  border='1'  cellspacing=0 width=100 height=150>

</table>

<?php $this->endWidget(); ?>

<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'Training')); ?>

<table  border='1'  cellspacing=0 width=100 height=150>

</table>

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

	<div class="row_buttons">

		<?php echo CHtml::submitButton('Save',array('name'=>($model->isNewRecord)?'create':'update')); ?>

	</div>


<?php $this->endWidget(); ?>



Any help will be much appreciated. Thanks in advance.

Hi.

In your action You have to send $activeTab to the view, so it should look like that:




$this->render('update',array(

		    'model'=>$model,

                    'activeTab'=>$activeTab,

		));



And now in your view your CTabView should be like that:




<?php $this->widget('system.web.widgets.CTabView', array('tabs'=>$tabParameters, 'activeTab'=>$activeTab)); ?>



That’s the only way to set active tab I know, but as I see You are using redirect, so it won’t work yet, but if u’ll use in that action before redirect:




Yii::app()->user->setState('nameofyourstate', array('someData'=>$somedata, 'anotherData'=>$anotherData));



and then in some action():




...

$yourarray = Yii::app()->user->getState('nameofyourstate');

$someData = $yourarray['someData'];

$anotherData = $yourdata['anotherData'];

...



(where ‘nameofyourstate’ ect are just sample names)

You can retrieve $activeTab in action() that will activate after redirecting and then send it in render() to the view.

Hope that can help You.