Zend 框架 2 添加新控制器 [英] zend framework 2 add new controller

查看:28
本文介绍了Zend 框架 2 添加新控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在 Module 中添加新控制器并通过 URL 调用它,我们需要更改哪些文件.

In which files do we need to make changes in order to add a new controller in Module and call it through URL.

有没有办法在不改变任何其他配置文件的情况下添加一个新的控制器文件并通过 url 调用它.

Is there a way in which we add a new controller file and call it through url without changing any other configuration files.

因为在控制器文件中每次添加或编辑时更改配置文件会非常繁琐.

As it will be very tedious to make changes in configuration files on every add or edit in controller files.

推荐答案

要创建新的控制器,您至少需要

To create a new controller, you have at least to

  • 创建控制器类
  • 确保您有一条符合您目的的匹配路线(您可以采用现有路线,也可以为特殊目的创建一条新路线)
  • 在模块的 module.config.php 中创建一个 controllers.invokables 条目.
  • create the controller class
  • make sure you've got a matching route that satisfies your purpose (you can take existing ones as well as create a new one for special purposes)
  • create a controllers.invokables entry in your module's module.config.php.

无法绕过这三个简单的步骤.我不明白为什么在添加控制器时调整 module.config.php 会出现问题——这就是配置文件的用途.包括打开、保存和关闭,这需要大约.10-15 秒.您不会创建数百个控制器,对吗?

There's no way around these three simple steps. I don't see why it should be a problem to adapt the module.config.php when you add a controller -- that's what config files are for. Including opening, saving und closing, this takes approx. 10-15 seconds. You aren't going to create hundreds of controllers, are you?

这篇关于Zend 框架 2 添加新控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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