I\'ve developed a basic MVC framework as a learning project in php--this is actually the second version of it, and I\'m trying to improve two aspects that the first version
The issue seems to be caused by over-simplified routing mechanism. The impression i get is that you are using simple explode()
to collect the parameters from URL. While this works just fin in basic examples, the setup will fail when you try to use a bit more advanced routing schemes.
Instead of splitting the string on /
, you should match it against regexp patterns. Basically, you define a list of patterns to match against and first match is used to populate the Request
instance.
In your situation would would have two patterns defined:
'#admin/(:?(:?/(?P<controller>[^/\.,;?\n]+))?/(?P<action>[^/\.,;?\n]+))?#'
'#(:?(:?/(?P<controller>[^/\.,;?\n]+))?/(?P<action>[^/\.,;?\n]+))?#'
If the first one fails, the second one would match.
P.S. You should know that controllers are not supposed to render output. Generation of response is responsibility of view instances. Views should be fully functional objects which contain presentation logic and can compose a response from multiple templates.