[Solar-talk] Handling 404 and exceptions
Paul M Jones
pmjones at paul-m-jones.com
Mon Mar 3 08:56:47 CST 2008
Hi Leo,
First, if I have not said so already: welcome to Solar, glad to have
you around. :-)
On Mar 1, 2008, at 10:30 , Leo Chiao wrote:
>> There are two places you can override that behavior, though:
>>
>> * Solar_Controller_Front::_notFound() executes when it can't find the
>> requested page controller.
>>
>> * Solar_Controller_Page::_forwardActionMethod() executes when it
>> can't
>> find a method for the requested action.
>>
>> (Looking at it now, the name _forwardActionMethod() describes exactly
>> what is happening, but is not very intuitive -- maybe i should rename
>> that to something more inviting. Maybe use Front::_pageNotFound and
>> Page::_actionNotFound() as the names?)
>
>
> Thanks for the quick reply Paul. I was aware of _notFound, but not
> of _forwardActionMethod. I do agree that your suggestions for
> renamed methods are more intuitive.
>
> Regarding the _notFound method, it doesn't appear to get called when
> a default page controller is defined. I could only get it to
> execute when no default page controller was specified. Is this
> expected behavior?
It is indeed the intended behavior. The idea is to have a fallback
that always works, no matter what, in the default case, even if you
have specified no routing or mappings. The only time you get a
resolution failure then is if you don't have a default at all.
Another of my reasons is that your main application could (and in my
case, frequently is) a simple page-display, where the only URI element
is the page-name. E.g. given a default Vendor_App_PageDisplay
controller, with a default action of `read`, you can see the foo-bar
page with this URI:
http://example.com/foo-bar
This would load a foo-bar.mdtxt file, process and wrap it, then
display. Then, no matter what other apps you have in your system, you
can always have access to the default application with small URIs.
Whether this reasoning makes sense or not, is a separate topic. ;-)
> This is actually what prompted me to ask the question about
> handling 404s and the reason for my "unique" Front Controller config.
>
> > $config['Solar_Controller_Front']['default'] = 'error';
> > $config['Solar_Controller_Front']['routing'] = array(
> > '' => 'Vendor_App_News',
> > 'error' => 'Vendor_App_Error'
> > );
I'll say again, that's quite nice. You could also add a 'news' =>
'Vendor_App_News' entry for explicit 'news' URIs.
> Specifying a default page controller caused that default controller
> to be displayed when accessing non-existent controllers, which is
> not what I wanted. I had wanted to use the default controller to
> define what would show up when accessing the base URL, but still
> expected the Front::_notFound to get executed when a controller
> wasn't found. In addition, I didn't see any documented examples of
> how people specified what controller to be run when accessing a
> project by the base url (ie. the main project's domain http://www.domain.com
> )
If you like, you can start a page on the new (as of today! :-) wiki <http://solarphp.org
> to add some documentation on how you have solved this particular
issue; it might be of help to others.
Please let me know if I've failed to address any of your concerns
here, and thanks for using Solar.
-- pmj
More information about the Solar-talk
mailing list