How To Redirect After Update

Hi everyone, I’m trying to redirect to admin view instead of normal view after my model has updated.

I tried this in my controller:


public function afterSave()

	{

	    

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

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

	'model'=>$model,

	));


        parent::afterSave();

	    

	}

But it doesn’t work… could anyone help me?

Thanks!

first afterSave() is not a controller method so you cannot call it in your controller. It is a method of CActiveRecord see docs: http://www.yiiframework.com/doc/api/1.1/CActiveRecord#afterSave-detail

To redirect in your controller use $this->redirect(…) in your controller action right after saving your stuff. Refer to the docs on how redirect works: http://www.yiiframework.com/doc/api/1.1/CController#redirect-detail

It takes 3 parameters but you are most likely to use just the first one which is the url to redirect to. Give it a try now and let me know if it works.