Awais Qarni
Awais Qarni

Reputation: 18016

zend undefined URL handling

hello I am working in Zend. I want to know some thing about undefined URL handling. I have a url like http://localhost/concierge/login and it has the following rule in url rule file.

'admin/login' =>array('login', array('module'=>'admin','controller' => 'index','action' => 'login'),array(),'login'),. It all works fine.

But if if change the url like http://localhost/concierge/lgin which I have not defined it goes to a blank page where an empty array is shown and there is written Page not Found. IT looks bad. I want to know if user writes any thing wrong in url, My application should show 404 error.

Now I want to know How can I achieve my task? Will I have to define an other rule for url rules files to handle all these errors? If so how this url rule will look like? And for controllers what should I do? Any help ?

Upvotes: 0

Views: 300

Answers (1)

Nilay Anand
Nilay Anand

Reputation: 340

I do this using the preDispatch hook of a front controller plugin.

public function preDispatch(Zend_Controller_Request_Abstract $request) { $disp = Zend_Controller_Front::getInstance()->getDispatcher();

    if ( !$disp->isDispatchable($request) ) { 
            $request->setModuleName('default'); 
            $request->setControllerName('error'); 
            $request->setActionName('error404'); 
    } 

}

if the thing doesn't exist ( /registerxxx instead of /register for example ) then they get bounced to a 404 page. It has worked so far for me.

Upvotes: 1

Related Questions