Using default parameters for 404 error (PHP with mvc design)?

Posted by user1175327 on Programmers See other posts from Programmers or by user1175327
Published on 2012-06-27T12:04:07Z Indexed on 2012/06/27 15:25 UTC
Read the original article Hit count: 272

Filed under:
|
|

I have a custom made Framework (written in PHP). It all works very good, but i have some doubts about a certain thing.

Right now when a user call this url for example:

http://host.com/user/edit/12

Which would resolve to:

  • user = userController
  • edit = editAction() in userController
  • 12 = treated as a param

But suppose the controller 'userController' doesn't exist. Then i could throw a 404. But on the other hand, the url could also be used as params for the indexController (which is the default controller). So in that case:

  • controller = indexController
  • user = could be an action in indexController, otherwise treated as a param
  • edit = treated as a param
  • 12 = treated as a param

That is actually how it works right now in my framework. So basically, i never throw a 404.

I could ofcourse say that only params can be given if the controller name is explicitly named in the URL. So if i want the above url:

http://host.com/user/edit/12

To be invoked by the indexController, in the indexAction. Then i specifically have to tell what controller and action it uses in the URL.

So the URL should become:

http://host.com/index/index/user/edit/12
  • index = indexController
  • index (2nd one) = the action method
  • user = treated as a param
  • edit = treated as a param
  • 12 = treated as a param

That way, when a controller doesn't exist, i don't reroute everything as a param to the index controller and simply throw a 404 error.

Now my question is, which one is more preffered? Should i allow both options to be configurable in a config file? Or should i always use one of them. Simply because that's the only and best way to do it?

© Programmers or respective owner

Related posts about php

Related posts about mvc