Have one controller function call a different controller function in CakePHP 1.2
How do I get my Sea开发者_StackOverflowrch
controller with doSearch()
function internally to call getTitles()
function in my Titles
controller?
The short answer is, you shouldn't do this. You should be moving that to your Title model or maybe put it in a component or helper for reuse.
If you're sure you want to call the controller directly, Cake does provide a method for this
http://book.cakephp.org/2.0/en/controllers.html#Controller::requestAction
there is no reason to go to a another controller.
controller should mostly call methods from models. so there should be a Title Model that contains the method you need.
Post your code if you need more help.
So the answer, for future reference, is:
$this->requestAction('/controller/action/params');
Making functionality that you want to reuse components does not always work well as Cakephp, does not bring in Models and find(), and set->$this etc. One other way to go is make your core functionality a core function then return $results, call this functionality like $results =$this->function_within_controller(); so you can reuse the functionality this way. I run into alsorts of errors when sometimes trying to use components, in Cakephp, components is good for using standalone php scripts and code.
精彩评论