Reputation: 9592
I want to execute:
$this->view->setVar("menus",$menus);
before the view gets executed.
$menus is an array that can be added by different controllers.
Finally before executing the view i want to put the menus var in the view.
Upvotes: 0
Views: 468
Reputation: 13240
Pick one of the Dispatcher's Events that best suits your needs, then add a method in your controller with same name of the picked event. You can implement this method on your controller base class. For example, adding the $menus
in all views for the indexAction
:
class MenuControllerBase extends \Phalcon\Mvc\Controller
{
public function beforeExecuteRoute($dispatcher)
{
if($dispatcher->getActionName() == 'index') {
if(isset($this->menus)) {
$this->view->menus = $this->menus;
}
}
}
}
Upvotes: 2