How to call another controller action method

Hai to all,

I have two controller and action


   -addevent(this is action).

   -viewevent(this is another action).


    -addcomment(this is action).

    -viewcomment(this is another action).

My question is, how can i call viewevent action inside on viewcomment action.

You cannot crosscall actions, but you can always have views nested. By calling CController::renderPartial, you can always embed viewevents’ views in your main action’s view files.

Hai pestaa,

Thanks for your reply.

please tell briefly, am not understand. how to call another controller function.

You can’t call another function from different controller. (It is strongly recommended to create a workaround in order to create your code clean.)

As I understand your problem, you want to display events even when comments are shown.

Instead of dealing with numerous actions during a single request, it is better to embed other views.

In your comments’ view files you can do (as far as I know this works; correction, if needed, is appreciated):


echo $this->renderPartial('../event/viewEvents', array('data'=>...));


Edit this line of code so that it suits your environment (different view name, passed variables, etc.)

Is it clear now?

As far as I understand with renderPartial we include a view and we can pass variables to it. But let’s have the following scenario:

I have a site with several pages: home, about me, contacts. And in "home" and "about me" I want to show a section with the latest news. This section (news) has no connection with the data of "home" and "about me" and it should be separated in a different controller/view and it should be included within the "home"/"about me" views. But how do I do that if I cannot call another action?

I’m a newbie to this framework so please be kind to me :)

@Nikolay Kolev

this question is asked all the time. I believe what you need is widget. Look up widgets in the docs

Is it possible to apply access control (accessRules) for the widget?