Zend 中的灵活路由
我还没有经常使用 Zend Router,所以不确定这有多困难或多容易,但我认为 Zend 很灵活,所以它必须有一种方法可以轻松地做到这一点。
因此,我创建了一个具有 2 个操作 actone
和 acttwo
的控制器 Cont
。这自然给了我
//the default index controller
site.com/
site.com/index/index
//and my controller
site.com/cont/index
site.com/cont/actone
site.com/cont/acttwo
是否有一种方法可以使用看起来像这样的路由访问 cont
控制器中的 actone
操作,
site.com/actone
我意识到我可以通过创建来获得这种外观一个名为 Actone
的单独控制器,这将是其 index
操作,但此 actone
操作逻辑上属于 Cont
控制器,所以我只想给出该路径的外观。
I haven't used the Zend Router much yet so not sure how difficult or easy this is, but I think Zend is flexible so it's got to have a way to do this easily.
So I create a controller Cont
with 2 actions actone
and acttwo
. This naturally gives me
//the default index controller
site.com/
site.com/index/index
//and my controller
site.com/cont/index
site.com/cont/actone
site.com/cont/acttwo
Is there a way I can access the actone
action which is in the cont
controller using a route that looks like this
site.com/actone
I realize I could get this look by creating a separate controller called Actone
and this would be its index
action but this actone
action logically belongs to the Cont
controller, so I want to just give the appearance of that path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建自定义路由...
通过 application.ini 的 - 路由器应用程序资源
或者直接向路由器添加一个。
You can create a custom route...
Via application.ini's - Router Application Resource
Or by adding one directly to the router.
如果您可以将您的
Cont
控制器设置为默认控制器,则可能会成功。 IIRC 这是在 Zend_Controller_Dispatcher_Abstract 中,有 setDefaultControllerName() 以及 setDefaultAction() 和 setDefaultModule()。If you could make your
Cont
controller the default controller that would probably do the trick. IIRC this is in Zend_Controller_Dispatcher_Abstract, there's setDefaultControllerName() as well as setDefaultAction() and setDefaultModule().