Question

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?

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top