开发者

One 404 page for Admin controller and other 404 page for other controllers, how?

开发者 https://www.devze.com 2023-01-13 12:40 出处:网络
I\'m very new to MVC and now I\'m reading about CakePHP, ZendFramework etc. I can\'t understand how can I se开发者_如何学编程t one 404 page for missing Admin controller methods and other 404 page fo

I'm very new to MVC and now I'm reading about CakePHP, ZendFramework etc.

I can't understand how can I se开发者_如何学编程t one 404 page for missing Admin controller methods and other 404 page for all other controller's methods.

Question is not about ZendFramework, CakePHP etc. - it's about MVC. I'm writing my own MVC and I can't realize how to implement this feature?


Zend Framework follows a simple approach.

There is by default a Front Controller plugin called ErrorHandler. When an exception is thrown from anywhere in your application the exception in being caught by the ErrorHandler plugin.

The plugin forwards the exception to a corresponding ErrorController that could actually render the error occurred.

So I am guessing any decision could be made on your ErrorController where you could take into consideration the module/controller/action point that the exception was thrown.


There can be within an MVC a concept of permissions, mostly it's considered authentication, but that doesn't have to be the case.

If you have an admin controller, then we assume you know who the users are when they are visiting your site. Thus we can use that to figure out which 404 page to use.

The other concept is there are admin "pages" and site "pages" thus, if someone is viewing your /admin/ section of the site, the admin 404 pages show up, otherwise the normal 404 pages show.


One solution, used by Zend Framework, is the concept of modules. Modules are groupings of controllers, models, views, and all their needed components that provide specific functionality. I usually have the main MVC implementation written and then add a module directory for my admin-specific MVC implementation. To increase code reuse, you can have the code extend the main application code.

More information on the strategies behind MVC modules can be found here: http://framework.zend.com/manual/en/zend.controller.modular.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号