如何保留默认的 Zend 路由

发布于 2024-11-07 02:28:58 字数 736 浏览 0 评论 0原文

我正在尝试设置有意义的网址,例如 http://www.site.com/company/department 但是它会破坏我现有的控制器/操作形状的 URL。

在我的引导程序中,我创建新路线如下:

$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route(":company/:dpt", array('controller'   => 'browse'));
$router->addRoute("browse", $route);

当我浏览到 http://www.site.com 时/ABC_Co/dry_goods 它会将我路由到 BrowseController 中的 IndexAction。伟大的!问题是我的其他与管理相关的 URL(例如 /company/create 等)也指向那里。

有没有办法让 Zend 首先执行其默认控制器/操作匹配,并仅在失败时恢复到浏览路由?

谢谢!

I am trying to setup meaningful URLs such as http://www.site.com/company/department however it hammers my existing URLs which are in the Controller/Action shape.

In my bootstrap, I create my new route as follows:

$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route(":company/:dpt", array('controller'   => 'browse'));
$router->addRoute("browse", $route);

When I browse to http://www.site.com/ABC_Co/dry_goods it routes me to IndexAction in BrowseController. Great! The problem is that my other admin-related URLS - such as /company/create, etc - are directing there too.

Is there some way to get Zend to do its default Controller/Action matching first, and revert to the Browse route only on failure?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我恋#小黄人 2024-11-14 02:28:58

路线是按后进先出的方式处理的,您需要执行以下操作:

$router->removeDefaultRoutes();
//add your routes
//add in the default route:
$route = new Zend_Controller_Router_Route(":module/:controller/:action"

相反,您可能只想在“浏览”路线中添加“静态”组件。这将使更具体:

$route = new Zend_Controller_Router_Route("browse/:company/:dpt", array('controller'   => 'browse'));

IMO,第二个是更好的选择

Routes are handled on LIFO, you'll need to do something like this:

$router->removeDefaultRoutes();
//add your routes
//add in the default route:
$route = new Zend_Controller_Router_Route(":module/:controller/:action"

Instead, you may just want to sonsider adding a "static" component to your "browse" route. That would make is more specific:

$route = new Zend_Controller_Router_Route("browse/:company/:dpt", array('controller'   => 'browse'));

IMO, the second one is the better option

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文