<i id='1gX2q'><tr id='1gX2q'><dt id='1gX2q'><q id='1gX2q'><span id='1gX2q'><b id='1gX2q'><form id='1gX2q'><ins id='1gX2q'></ins><ul id='1gX2q'></ul><sub id='1gX2q'></sub></form><legend id='1gX2q'></legend><bdo id='1gX2q'><pre id='1gX2q'><center id='1gX2q'></center></pre></bdo></b><th id='1gX2q'></th></span></q></dt></tr></i><div id='1gX2q'><tfoot id='1gX2q'></tfoot><dl id='1gX2q'><fieldset id='1gX2q'></fieldset></dl></div>

<legend id='1gX2q'><style id='1gX2q'><dir id='1gX2q'><q id='1gX2q'></q></dir></style></legend>

<small id='1gX2q'></small><noframes id='1gX2q'>

      <tfoot id='1gX2q'></tfoot>
        • <bdo id='1gX2q'></bdo><ul id='1gX2q'></ul>
      1. ZF2 - 将控制器名称放入布局/视图中

        时间:2023-10-02
      2. <legend id='udZ8q'><style id='udZ8q'><dir id='udZ8q'><q id='udZ8q'></q></dir></style></legend>
          <bdo id='udZ8q'></bdo><ul id='udZ8q'></ul>
            <i id='udZ8q'><tr id='udZ8q'><dt id='udZ8q'><q id='udZ8q'><span id='udZ8q'><b id='udZ8q'><form id='udZ8q'><ins id='udZ8q'></ins><ul id='udZ8q'></ul><sub id='udZ8q'></sub></form><legend id='udZ8q'></legend><bdo id='udZ8q'><pre id='udZ8q'><center id='udZ8q'></center></pre></bdo></b><th id='udZ8q'></th></span></q></dt></tr></i><div id='udZ8q'><tfoot id='udZ8q'></tfoot><dl id='udZ8q'><fieldset id='udZ8q'></fieldset></dl></div>

            • <tfoot id='udZ8q'></tfoot>
              1. <small id='udZ8q'></small><noframes id='udZ8q'>

                    <tbody id='udZ8q'></tbody>
                  本文介绍了ZF2 - 将控制器名称放入布局/视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我知道使用 ZF1,您将使用自定义视图助手检索模块/控制器名称,该助手将获取单例 frontController 对象并在那里获取名称.

                  I know with ZF1 you would retrieve the module/controller name using custom View Helpers that would get the singleton frontController object and get the name there.

                  使用 ZF2,因为它们消除了框架的很多单例性质并引入了 DI,我在其中为该模块中的所有控制器指定了别名......我可以想象我会通过访问 DI 或也许将当前名称注入到布局中.

                  Using ZF2 as they've abolished alot of the singleton nature of the framework and introduced DI where I've specified aliases for all of my controllers within this module... I can imagine I would get it through accessing the DI or perhaps injecting the current name into the layout.

                  任何人都知道你会怎么做.我想有一百种不同的方法,但是在嗅探了几个小时的代码之后,我真的无法弄清楚它现在是如何完成的.

                  Anyone got any idea how you would do it. I guess there a hundred different ways but after sniffing about the code for a few hours I can't really figure out how its meant to be done now.

                  我想要控制器名称的原因是将其作为特定控制器样式的类添加到主体中.

                  The reason I wanted the controller name is to add it to the body as a class for specific controller styling.

                  谢谢,多姆

                  推荐答案

                  ZF2 出来了,骨架也出来了.这是在骨架顶部添加的,所以它应该是你最好的例子:

                  ZF2 is out and so is the skeleton. This is adding on top of the skeleton so it should be your best example:

                  内部模块.php

                  public function onBootstrap($e)
                  {
                      $e->getApplication()->getServiceManager()->get('translator');
                      $e->getApplication()->getServiceManager()->get('viewhelpermanager')->setFactory('controllerName', function($sm) use ($e) {
                          $viewHelper = new ViewHelperControllerName($e->getRouteMatch());
                          return $viewHelper;
                      });
                  
                      $eventManager        = $e->getApplication()->getEventManager();
                      $moduleRouteListener = new ModuleRouteListener();
                      $moduleRouteListener->attach($eventManager);
                  }
                  

                  实际的 ViewHelper:

                  The actual ViewHelper:

                  // Application/View/Helper/ControllerName.php
                  
                  namespace ApplicationViewHelper;
                  
                  use ZendViewHelperAbstractHelper;
                  
                  class ControllerName extends AbstractHelper
                  {
                  
                  protected $routeMatch;
                  
                      public function __construct($routeMatch)
                      {
                          $this->routeMatch = $routeMatch;
                      }
                  
                      public function __invoke()
                      {
                          if ($this->routeMatch) {
                              $controller = $this->routeMatch->getParam('controller', 'index');
                              return $controller;
                          }
                      }
                  }
                  

                  在您的任何视图/布局中

                  Inside any of your views/layouts

                  echo $this->controllerName()
                  

                  这篇关于ZF2 - 将控制器名称放入布局/视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:向 Zend Forms 添加一些 html 下一篇:实用 Zend_ACL + Zend_Auth 实现和最佳实践

                  相关文章

                  最新文章

                      <bdo id='qrpbw'></bdo><ul id='qrpbw'></ul>
                  1. <legend id='qrpbw'><style id='qrpbw'><dir id='qrpbw'><q id='qrpbw'></q></dir></style></legend>

                      <i id='qrpbw'><tr id='qrpbw'><dt id='qrpbw'><q id='qrpbw'><span id='qrpbw'><b id='qrpbw'><form id='qrpbw'><ins id='qrpbw'></ins><ul id='qrpbw'></ul><sub id='qrpbw'></sub></form><legend id='qrpbw'></legend><bdo id='qrpbw'><pre id='qrpbw'><center id='qrpbw'></center></pre></bdo></b><th id='qrpbw'></th></span></q></dt></tr></i><div id='qrpbw'><tfoot id='qrpbw'></tfoot><dl id='qrpbw'><fieldset id='qrpbw'></fieldset></dl></div>
                      <tfoot id='qrpbw'></tfoot>

                      <small id='qrpbw'></small><noframes id='qrpbw'>