简体   繁体   中英

Zend Framework - routes - all requests to one controller except requests for existing controllers

How to create route that accept all requests for unexsting controllers, but leave requests for existing.

This code catch all routes

$route = new Zend_Controller_Router_Route_Regex('(\\w+)', array('controller' => 'index', 'action' => 'index')); $router->addRoute('index', $route);

how should I specify route requests like /admin/* or /feedback/* to existing adminController or feedbackController?

You should not create a route to handle that. The error controller will take care of all three kinds of the following errors:

  • Controller does not exist
  • Action does not exsist
  • No route matched

Take a look at the documentation on how to use it correctly:

http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler.fourohfour

I found only the way - not to add route in case current request is about admin area

$request = $frontController->getRequest();               

if (!preg_match('/knownController/', $request->getRequestUri())){
    $router->addRoute('index', new Zend_Controller_Router_Route_Regex('(.*)', array('controller' => 'index', 'action' => 'index')));  
}    

You can also use the ErrorController to do a similar thing. Maybe if you dig into the way they implement the plugin it will help you build something that meets your needs closely?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM