简体   繁体   English

phalcon-执行视图事件之前?

[英]phalcon - before executing view event?

I want to execute: 我要执行:

$this->view->setVar("menus",$menus); $这 - >视图 - > SETVAR( “菜单”,$菜单);

before the view gets executed. 在执行视图之前。

$menus is an array that can be added by different controllers. $ menus是可以由不同控制器添加的数组。

Finally before executing the view i want to put the menus var in the view. 最后,在执行视图之前,我想将菜单var放入视图中。

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 : 例如,在所有视图中为indexAction添加$menus

class MenuControllerBase extends \Phalcon\Mvc\Controller
{
  public function beforeExecuteRoute($dispatcher)
  {
    if($dispatcher->getActionName() == 'index') {
      if(isset($this->menus)) {
        $this->view->menus = $this->menus;
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM