3
votes

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 would like to route to the "index" controller and "index" action by default

3
Do you have this code in your bootstrap? Zend_Controller_Front::getInstance()->getRouter()->removeDefaultRoutes(); - Lenin Raj Rajasekaran
I dont have that code... - shasi kanth
Do you have ErrorController setup in your project? - Lenin Raj Rajasekaran

3 Answers

3
votes

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.

2
votes

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.

1
votes

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');
    }

}

?>