• <small id='oHKmR'></small><noframes id='oHKmR'>

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

      1. <legend id='oHKmR'><style id='oHKmR'><dir id='oHKmR'><q id='oHKmR'></q></dir></style></legend>

        Zend Framework:控制器对象中的 init() 和 preDispatch() 函数有什么区别?

        Zend Framework: What are the differences between init() and preDispatch() functions in controller objects?(Zend Framework:控制器对象中的 init() 和 preDispatch() 函数有什么区别?)

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

              <small id='7niaJ'></small><noframes id='7niaJ'>

                <tbody id='7niaJ'></tbody>

              • <bdo id='7niaJ'></bdo><ul id='7niaJ'></ul>
                  <legend id='7niaJ'><style id='7niaJ'><dir id='7niaJ'><q id='7niaJ'></q></dir></style></legend>
                • 本文介绍了Zend Framework:控制器对象中的 init() 和 preDispatch() 函数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我认为执行的顺序是init()、preDispatch()然后action()被调用.

                  1. 我是否应该在 init() 或 preDispatch() 中初始化我的变量,这些变量在所有操作中都很常见?我见过有人使用这两个函数进行初始化.可能顾名思义,它应该在 init() 中完成,但是在 preDispatch() 中会发生什么样的事情?

                  2. init() 和 preDispatch() 函数调用之间会发生什么?

                  解决方案

                  首先为 Zend_Controller_Plugin_Abstract 的实例调用 preDispatch().这里有请求和响应对象,因此您可以过滤请求或使用请求中的信息做一些准备.

                  Zend_Controller_Action

                  init() 接下来作为构造函数的一部分被调用.它可以帮助您初始化控制器,而无需覆盖和重复构造函数的签名(Zend_Controller_Action::__contruct()).

                  控制器的preDispatch() 方法在这里被调用.您可以调用 $request->setDispatched(false) 来跳过当前操作 - 不确定您是否可以在 init()

                  中执行此操作

                  然后调用您的操作方法(例如viewAction()).在这里,您可以执行正常的工作,例如从模型中获取内容并填充视图.

                  所以区别现在应该很清楚了:

                  • 如果您想在所有操作之前执行某些操作 - 将其放入插件并使用其中一个钩子(除了 preDispatch() 之外,还有 routeStartup 和 其他),
                  • 如果你想在控制器中的每个动作之前 - initpreDispatch(),
                  • 如果仅针对单个操作 - 操作本身.
                  <块引用>

                  init()preDispatch() 函数调用之间会发生什么?

                  几乎什么都没有 - preDispatch() 被执行了,如果你还没有调用 $request->setDispatched(false),动作就会被执行.>

                  I think the order of execution is init(), preDispatch() and then action() is called.

                  1. Should I initialize my variables, which are common among all actions, in init() or preDispatch()? I've seen people using both functions for initialization. Probably as the name suggests it should be done in init() but then what kind of stuff would go in preDispatch()?

                  2. What happens between init() and preDispatch() function calls?

                  解决方案

                  First preDispatch() is called for instances of Zend_Controller_Plugin_Abstract. Here you have the request and response objects, so you might filter the request or do some preparation using the information from the request.

                  init() of the Zend_Controller_Action is called next as part of the constructor. It's there to help you initialize your controller, without having to override and repeat the signature of the constructor (Zend_Controller_Action::__contruct()).

                  The controller's preDispatch() method is called here. You can call $request->setDispatched(false) to skip the current action - not sure if you can do that in init()

                  Then your action method is called (viewAction() for example). Here you do your normal work like fetching stuff from the model and populating the view.

                  So the distinction should now be clear:

                  • If you want something to be executed before all actions - put it in a plugin and use one of the hooks (besides preDispatch() there is routeStartup and others),
                  • if you want before every action in a controller - init or preDispatch(),
                  • if only for a single action - the action itself.

                  What happens between init() and preDispatch() function calls?

                  Almost nothing - preDispatch() is executed, and if you haven't called $request->setDispatched(false), the action is executed.

                  这篇关于Zend Framework:控制器对象中的 init() 和 preDispatch() 函数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)

                  <tfoot id='bw31j'></tfoot><legend id='bw31j'><style id='bw31j'><dir id='bw31j'><q id='bw31j'></q></dir></style></legend>
                    <tbody id='bw31j'></tbody>

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

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

                            <bdo id='bw31j'></bdo><ul id='bw31j'></ul>