calling a controller from another one

how can i call a controller and action from another controller?

You can call the action from another controller such as

$this->render('anotherController/action', array('model'=>$model));

You don’t want to do this!!

Use the model instead.

Keep your controllers skinny and the models fat.

What are you trying to do? :)

thanks betto.

I have a page controller and i want to call the home page from siteController index action, do you have a better approach?

In that case, a simple redirect will do the trick.

What is the default controller ?

Did you check out a standard Yii web application as generated by yiic ?

yes I use the standard generated yii web app, and the default one is siteController.


As jacmoe said use redirect. Why don’t you want to use redirect?

i did now and it worked, thank you all :)

Awesome, exactly the answer I was looking for.

Can I do this with renderPartial and have it show up in the same view? I’m hoping to be able to use, within views of a given model, partial views from a different model (i.e. renderPartial for a “post” model within a view corresponding to the “thread” model/controller).

How about this:


$controller_instance = new SiteController("Site");