Yii Framework Forum: How to call another controller action method - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

How to call another controller action method Rate Topic: -----

#1 User is offline   velsa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 21-June 09
  • Location:canada,US

Posted 08 August 2009 - 01:26 AM

Hai to all,
I have two controller and action
EventController,
-addevent(this is action).
-viewevent(this is another action).
CommentController
-addcomment(this is action).
-viewcomment(this is another action).

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

#2 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 08 August 2009 - 01:50 AM

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.
0

#3 User is offline   velsa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 21-June 09
  • Location:canada,US

Posted 08 August 2009 - 05:26 AM

Hai pestaa,
Thanks for your reply.
please tell briefly, am not understand. how to call another controller function.

View Postpestaa, on 08 August 2009 - 01:50 AM, said:

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.

0

#4 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 08 August 2009 - 05:55 AM

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):
<?php
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?
0

#5 User is offline   Nikolay Kolev 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 30-August 09

Posted 30 August 2009 - 03:42 PM

View Postpestaa, on 08 August 2009 - 05:55 AM, said:

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):
<?php
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 :)
0

#6 User is offline   jonah 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 733
  • Joined: 27-November 08
  • Location:California (US)

Posted 30 August 2009 - 03:54 PM

@Nikolay Kolev
this question is asked all the time. I believe what you need is widget. Look up widgets in the docs
http://php-thoughts.cubedwater.com - my bloggings about Yii
1

#7 User is offline   WallTearer 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 05-November 10
  • Location:Kiev, Troeschina

Posted 18 March 2011 - 10:46 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users