tags:

views:

57

answers:

3

Hello,

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

I can't understand how can I set 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?

Thank you

+1  A: 

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.

Viper_Sb
Yes, it is clear for me. But how can I implement this feature in code? For example, I have ErrorController; it's 404 method should determine what Controller was called and depending on this information - show one or another 404 page? Or how? We can even put this into FrontController's preDispatcher, but it's not good practice ,as far as I can see.
Kirzilla
I answered that way because of your statement "Question is not about ZendFramework, CakePHP etc. - it's about MVC." Models can work, but like you said, if you have an ErrorController, that can handle it can't it? If you use users, then look up the users permissions. If they're an admin show the admin controllers for the admins sections (if it's built like that). If you're doing it as sections, if the controller that errored is x then show normal error controller, if it's xAdmin then show admin error
Viper_Sb
+1  A: 

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

js1568
+1  A: 

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.

mobius