I want to call a controller function from a view. Is that possible in Cake PHP?
+3
A:
It is possible via the requestAction method, but it is not recommended due to a slight performance hit. Use it wisely.
As Xr noted in the comment, using requestAction often signifies design issues (MVC separation).
dr Hannibal Lecter
2009-07-08 09:21:41
Not exactly massive (not anymore, at least): http://cakedc.com/developer/mark_story/2009/02/27/benchmarking-requestaction .Still, if you want to call a controller function, you probably have problems with how you separated functionality between the parts of the MVC model.
Xr
2009-07-08 13:24:03
Thanks for pointing that out, I've completely missed that article.
dr Hannibal Lecter
2009-07-08 14:29:24
A:
Yeap use requestMethod with Caching
$out = Cache::read('savedincache');
if(empty($out)){
$out = $this->requestAction('/articles/myfunction');
Cache::write('savedincache', $out);
}
in /app/controllers/articles_controller.php
function myfunction(){
$out = $this->Article->find('all');
return $out
}
Aziz
2009-08-30 23:28:27