开发者

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->add开发者_开发知识库Route('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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜