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

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

    3. ZF2 - 将控制器名称放入布局/视图中

      ZF2 - Get controller name into layout/views(ZF2 - 将控制器名称放入布局/视图中)
    4. <i id='PherQ'><tr id='PherQ'><dt id='PherQ'><q id='PherQ'><span id='PherQ'><b id='PherQ'><form id='PherQ'><ins id='PherQ'></ins><ul id='PherQ'></ul><sub id='PherQ'></sub></form><legend id='PherQ'></legend><bdo id='PherQ'><pre id='PherQ'><center id='PherQ'></center></pre></bdo></b><th id='PherQ'></th></span></q></dt></tr></i><div id='PherQ'><tfoot id='PherQ'></tfoot><dl id='PherQ'><fieldset id='PherQ'></fieldset></dl></div>

    5. <small id='PherQ'></small><noframes id='PherQ'>

      • <bdo id='PherQ'></bdo><ul id='PherQ'></ul>

            <tbody id='PherQ'></tbody>

            <legend id='PherQ'><style id='PherQ'><dir id='PherQ'><q id='PherQ'></q></dir></style></legend>

                <tfoot id='PherQ'></tfoot>
                本文介绍了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 - 将控制器名称放入布局/视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                <legend id='q2fL2'><style id='q2fL2'><dir id='q2fL2'><q id='q2fL2'></q></dir></style></legend>

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

                    <tfoot id='q2fL2'></tfoot>

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

                        <tbody id='q2fL2'></tbody>
                        • <bdo id='q2fL2'></bdo><ul id='q2fL2'></ul>