Reputation: 8706
I've refactored some common behaviour that was repeated at the top of my Controller Actions into a preDispatch method - this is great, except that I'm having to live to general 400 errors even where there really should be a 404.
This is because the default preDispatch method doesn't know what Action is required - so I can't test to see if it exists and 404 if it doesn't.
Other than completely the Zend Controller's dispatch() method and passing the Action name to preDispatch - is there are better solution?
Update: please note, this is Zend Framework 1.10
Upvotes: 2
Views: 591
Reputation: 2869
. . . the default preDispatch method doesn't know what Action is required . . .
You can get the controller and action names in the preDispatch()
method by calling the following methods on the request object:
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$controller = $request->getControllerName();
$action = $request->getActionName();
// Do stuff
}
Upvotes: 0
Reputation: 4526
try something like this:
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$front = Zend_Controller_Front::getInstance();
if( $front->getDispatcher()->isDispatchable($request) ) {
// if dispatchable do some stuff
} else {
// else show the error
}
}
Upvotes: 2