I want to use "getpoll" ,which is action of users controller ,in another controller(events controller).
How can i use it?
in advance thanks...to all...
I want to use "getpoll" ,which is action of users controller ,in another controller(events controller).
How can i use it?
in advance thanks...to all...
You should write the db query of the getPoll()
action as a method in the poll model, that way in your user controller you can just call $this->User->Poll->getPolls()
to grab the polls, and if associations are setup correctly, $this->Event->Poll->getPolls()
from your events controller.
For example in your poll model:
public function getPoll($userId = null) {
return $this->find('all', array(..));
}
You can use requestAction method of the controller:
$this->requestAction('/comments/latest');
you can call it differently depending on your needs for details look for the link:
Link to CookBook: Controller requestAction Method
You should write the db query of the getPoll()
action as a method in the poll model, that way in your user controller you can just call $this->User->Poll->getPolls()
to grab the polls, and if associations are setup correctly, $this->Event->Poll->getPolls()
from your events controller.
For example in your poll model:
public function getPoll($userId = null) {
return $this->find('all', array(..));
}
You could share a common piece of code between controllers with components.
The cookbook states:
If used without caching requestAction can lead to poor performance. It is rarely appropriate to use in a controller or model. http://book.cakephp.org/2.0/en/controllers.html
And this post show a different and better approach
© 2022 - 2024 — McMap. All rights reserved.