开发者

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('co开发者_开发百科ntroller'=>'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')
);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜