Route all requests through PageController except existing controllers (Zend Framework)

亡梦爱人 提交于 2019-12-05 12:46:38

Zend routes work in order - if you add a second route after your first, it will take precedence if it matches. In my own Zend project I've got a bunch of routes, the first of which is much like yours, a catch all route. However, anything below it that matches the url overrides it - so just try adding slightly more specific routes (if all your /user/ requests go to your user_controller, add a /user/* route)

Making your pages controller default, and adding a route for every existing controller might get very messy very quickly, and you have to change it every time you add a controller.

An alternative might be to customize the ErrorController. Since in the event of a missing controller, the framework will throw a Zend_Controller_Dispatcher_Exception which will propagate through to the error handler as an EXCEPTION_NO_CONTROLLER, you can just check for that type and forward to your pages controller.

If you're feeling masochistic, you could also write a custom route class that returns false if the controller exists and handles all routes if not. This is probably the best option in terms of roles and responsibilities, but also the most complex to implement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!