i am using zend framework for my application and i have used few regex routes for routing the users to specific controllers and actions based on the options in url.
But when a url pattern is not matched, i get a 404 error like: Page Not Found.
How can i specify configuration, such that when the regex route does not match the specified urls, the control routes to a default controller and action?
FYI, i 开发者_C百科would like to route to the "index" controller and "index" action by default
You could create your own "catch all" Route and place this in to the Router so that it runs after the regex one. IIRC, the Router component loops the installed Routes (backwards?) and the first one that returns true triggers the process to exit. Your "catch all" Route would always return true.
I am using ACL
to generate custom error
class Management_Access extends Zend_Controller_Plugin_Abstract{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
....
....
....
....
$controller = $request->controller;
$action = $request->action;
if (!$acl->has($controller)) {
$request->setControllerName('error');
$request->setActionName('notfound');
}
Modifying it might help you.
Solution 1:
Add the following parameter in your Front Controller in your bootstrap.
$front->setParam('useDefaultControllerAlways', true);
Solution 2:
Modify your ErrorController like the following,
class ErrorController extends Zend_Controller_Action {
public function errorAction() {
$this->_forward('index', 'index');
}
}
?>
精彩评论