[英]Nesting controllers in Zend Framework
I'm building a Zend Framework application and created some controllers which correspond to database tables and hold methods for performing CRUD operations on those tables. 我正在构建一个Zend Framework应用程序,并创建了一些与数据库表相对应的控制器,并包含用于在这些表上执行CRUD操作的方法。
I've just started working on the Companies
controller which holds methods for adding, editing and deleting companies. 我刚刚开始使用
Companies
控制器,其中包含用于添加,编辑和删除公司的方法。 For this we can use the traditional controller/action
URL pattern: 为此,我们可以使用传统的
controller/action
URL模式:
http://example.com/companies/add
http://example.com/companies/edit/some-company
The problem is that for each Company
we also need to manage its Contacts
and Machines
: 问题在于,对于每个
Company
我们还需要管理其Contacts
和Machines
:
http://example.com/companies/some-company/machines/add
http://example.com/companies/another-company/contacts/edit/some-contact
I just can't get my head around how to manage this in Zend Framework. 我只是无法理解如何在Zend Framework中进行管理。 Should I 'nest' the controllers through routing, or should I make use of modules?
我应该通过路由“嵌套”控制器,还是应该使用模块? Any help would be very much appreciated.
任何帮助将不胜感激。
You could easily write custom routes to handle this. 您可以轻松编写自定义路由来处理此问题。 For example, this:
例如,这:
http://example.com/companies/some-company/machines/add
would become in your .ini file: 会变成您的.ini文件:
routes.machine.route = "companies/:companyname/machines/:action"
routes.machine.defaults.controller = machines
routes.machine.defaults.action = index
This will point the url to the machines
controller and sets companyname
as a GET-var. 这将链接指向
machines
控制器,并将companyname
为GET-VAR。
You can easily change this to suit any form you like. 您可以轻松更改此设置以适合您喜欢的任何形式。
with zend framework default router , your url's didn't work. 使用zend Framework默认路由器时,您的网址无效。 this links must work:
此链接必须有效:
http://example.com/companies/add
http://example.com/companies/edit/id/some-company
http://example.com/companies/addmachines/id/some-company//
http://example.com/companies/contacts/mod/edit/companyid/another-company/
format: 格式:
http://yoursite.com/Module(if available)/Controller/Action/param1/val1/param2/val2/?param3=val3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.