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

    <tfoot id='iunA2'></tfoot>

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

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

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

        在zend框架中调用其他控制器的成员函数?

        时间:2023-10-03
        <legend id='iALJw'><style id='iALJw'><dir id='iALJw'><q id='iALJw'></q></dir></style></legend>

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

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

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

                    <tbody id='iALJw'></tbody>
                  本文介绍了在zend框架中调用其他控制器的成员函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  是否可以在zend框架中调用另一个控制器的成员函数,如果是,那么如何?

                  Is it possible to call the member function of another controller in zend framework, if yes then how?

                  <?php
                  class FirstController extends Zend_Controller_Action {
                      public function indexAction() {
                           // general action 
                      }   
                  
                      public function memberFunction() {
                           // a resuable function
                      }
                  }
                  

                  这是另一个控制器

                  <?php
                  class SecondController extends Zend_Controller_Action {
                      public indexAction() {
                           // here i need to call memberFunction() of FirstController
                      }
                  }
                  

                  请解释我如何从第二个控制器访问 memberFunction().

                  Please explain how i can access memberFunction() from second controller.

                  更好的想法是定义一个 AppController 并使所有常用控制器扩展 AppController,从而进一步扩展 Zend_Controller_Action.

                  Better idea is to define a AppController and make all usual controllers to extend AppController which further extends Zend_Controller_Action.

                  class AppController extends Zend_Controller_Action {
                      public function memberFunction() {
                           // a resuable function
                      }
                  }
                  
                  class FirstController extends AppController {
                      public function indexAction() {
                           // call function from any child class
                           $this->memberFunction();
                      } 
                  }
                  

                  现在 memberFunction 可以从扩展 AppController 的控制器调用,作为简单继承的规则.

                  Now memberFunction can be invoked from controllers extending AppController as a rule of simple inheritance.

                  推荐答案

                  控制器并非旨在以这种方式使用.如果您想在当前控制器之后执行另一个控制器的动作,请使用_forward()方法:

                  Controllers aren't designed to be used in that way. If you want to execute an action of the other controller after your current controller, use the _forward() method:

                  // Invokes SecondController::otherActionAction() after the current action has been finished.
                  $this->_forward('other-action', 'second');
                  

                  请注意,这只适用于操作方法(memberAction"),不适用于任意成员函数!

                  Note that this only works for action methods ("memberAction"), not arbitrary member functions!

                  如果 SecondController::memberFunction() 做了一些跨多个控制器需要的事情,把代码放在一个动作助手或库类中,这样两个控制器就可以访问共享的功能而不必依赖互相依赖.

                  If SecondController::memberFunction() does something that is needed across multiple controllers, put that code in a action helper or library class, so that both controllers can access the shared functionality without having to depend on each other.

                  这篇关于在zend框架中调用其他控制器的成员函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 Zend 框架时显示 php 错误 下一篇:如何使用 Zend_Db 添加多于一行?

                  相关文章

                  最新文章

                  <tfoot id='eApe3'></tfoot>

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

                  1. <small id='eApe3'></small><noframes id='eApe3'>

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