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.
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;
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.