[Solar-talk] 404 Not found and handling of non-existing controllers/action

Adrian Videnie avidenie at gmail.com
Fri Nov 23 08:31:23 CST 2007


Hello!

First of all, I want to congratulate everyone involved in development of 
such a nice project like Solar.
Thank you and keep up the good work :).

I want to make a small suggestion on how the framework handles invalid 
controllers/action.
 From what I noticed, the front controller tries to dispatch to the 
controller specified by the first uri segment. If it fails, a default 
page controller can be specified for the front controller in the config 
file.
If the default is not set, a 404 page will show.

That means that current implementation will show the default controller 
in all cases (if that's set).
I understand why some people might want to do this, but I prefer to show 
the user a nice 404 Not found page, eventually with a nice layout and a 
site map to provide them alternatives.
It is also nice for search engines to know that the url it tries is not 
valid.

After discussions on #solarphp, I think a very simple implementation of 
that behaviur would be another setting for Solar_Controller_Front, let's 
call it default_if_uri_controller_is_not_empty for example. By default, 
if not set in config, it can take the value of default, so that the 
behaviur is the same as it is now (backward compatibility). If I specify 
a value for it, it should try to dispatch to that particular controller 
instead. If I pass an invalid value to it, the _notFound() method will 
be called, with the default 404 message (to prevent loops).

This way, it's flexible enough and it preserves backward compatibility 
with existing application.

Exactly the same thing happens with the page controller, via the 
$_action_default property in this case (not a config setting).
It would be very nice to only fall back to the default action specified 
here only if I didn't provide an action via the uri. If I did and it 
doesn't exists, I want to be able to show a 404 eror page.

For example, let's say I indicated that 'index' is my default action in 
controller 'example'.

http://domain.tld/example/ <http://domain.tld/controller1/> - executes 
the actionIndex method (correct)
http://domain.tld/example/non-existing-action 
<http://domain.tld/controller1/> - executes default action (which is not 
what i want, I would like to be able to forward to the 404 page somehow 
- for example, by not falling to the default action and throwing 
exception caught in _exceptionDuringFetch() method, which I can use to 
forward to the 404 Not found controller).

I can get the behavior I want by extending the front and page 
controllers and adding a simple check for the uri segment for 
controller, respectively action to be not empty. But I think it would be 
very nice to have this options in the framework itself.

Let me know what you think!

Thanks,

Adrian Videnie










More information about the Solar-talk mailing list