How to use find('all') in Views – CakePHP-Collection of common programming errors

Inside your Menu model create a method, something like getMenu(). In this method do your find() and get the results you want. Modify the results as you need and like to within the getMenu() method and return the data.

If you need that menu on every page in AppController::beforeFilter() or beforeRender() simply do

$this->set('menu', ClassRegistry::init('Menu')->getMenu());

If you do not need it everywhere you might go better with using requestAction getting the data using this method from the Menus controller that will call getMenu() from the model and return the data. Setting it where you need it would be still better, if you use requestAction you also want to cache it very likely.

Originally posted 2013-11-09 21:42:24.