简体   繁体   中英

Zend Framework Zend_Controller_Router_Route (catch all controllers before routing param)

My apologies for the title of this question not being very descriptive but the truth is I'm not too sure what the correct terminology for this question is. I am new to using Zend Framework.

Imagine this url: www.foo.com/bar The code below takes "bar" and passes it through to the index controller's load action. However I have another controller called "mypresentation" which is getting ignored now the router below has been added to the Bootstrap.

$route = new Zend_Controller_Router_Route(
    '/:prospect',
    array('controller'=>'index', 'action' => 'load'));

$router->addRoute('load', $route);

How to I make the router ignore hardcoded controllers ?

Any help is much appreciated and I'll change the title if I can when I have more information.

Alex.

FIX:

$prospectRoute = new Zend_Controller_Router_Route(
    '/:prospect',
    array('controller'=>'index', 'action' => 'load')
);

$route2 = new Zend_Controller_Router_Route(
    'mypresentation',                        
     array('controller' => 'mypresentation') 
);

$router->addRoute('index', $prospectRoute);
$router->addRoute('mypresentation', $route2);      

Add another route before this one, to catch any routes to the mypresentation controller first. It runs through the routes in order till it finds the first one it matches.

$route2 = new Zend_Controller_Router_Route(
    'mypresentation',                        // what's typed in URL
     array('controller' => 'mypresentation') // send here
);

$router->addRoute('mypresentation', $route2);
$router->addRoute('load', $route);           // Your original route

If you want to catch all controllers, use

$route3 = new Zend_Controller_Router_Route(
    ':controller',                       
     array('controller' => ':controller')
);

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