基于控制器更改 Zend 框架默认操作 [英] changing zend framework default action based on the controller

查看:22
本文介绍了基于控制器更改 Zend 框架默认操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道您可以在 application.ini 中的 Zend Framework 中设置自定义默认操作:

So I know that you can set a custom default action in Zend Framework in the application.ini:

resources.frontController.defaultAction = "something"

但是如果我希望这个默认操作取决于控制器怎么办?所以控制器A的默认动作是B,控制器C的默认动作是D,等等如何配置控制器以采用这些默认操作参数?需要什么代码,我应该把它们放在哪里?

But what if I want this default action to be contingent on the controller? So controller A's default action will be B, controller C's default action will be D, etc how do I configure the controllers to take these default action parameters? What piece of code is needed and where should I place them?

推荐答案

您可以在 Bootstrap.php 中添加如下内容:

You can add in your Bootstrap.php something like this:

   protected function _initRoutes()
   {
      $Router = Zend_Controller_Front::getInstance()->getRouter();

      $Route = new Zend_Controller_Router_Route(
                      '/controller1',
                      array(
                          'action' => 'customaction1'
                      )
      );
      $Router->addRoute('c1', $Route);

      $Route = new Zend_Controller_Router_Route(
                      '/controller2',
                      array(
                          'action' => 'customaction2'
                      )
      );
      $Router->addRoute('c2', $Route);

      [...]
   }

这篇关于基于控制器更改 Zend 框架默认操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆