检测 zend router 变量中的变量类型

发布于 2024-12-14 04:18:12 字数 1033 浏览 6 评论 0原文

所以我使用 zend_router 将控制器中的索引页路由到除索引操作之外的操作:

$route = new Zend_Controller_Router_Route(
                         '/controller/:page',
                          array(
                              'action' => 'not-index',
                              'controller' => 'controller',
                              'page' => 1,
                              ),
         );

我将 :page 添加到路径中的原因是因为该索引中有分页,我希望有即使用户只在浏览器中输入“/controller”,分页器也能工作,所以它必须在那里(参见:http://www.joewebster.co.uk /articles/zend-framework/7-zend-pagination-and-zend-router)...

问题是...现在控制器中的其他操作也会重定向到该页面,而不是重定向到正确的行动

所以假设我输入'/controller/other-action' 到浏览器,由于该路由定义,它会转到 'controller/not-index',页面 = other-action 而不是 'controller/other-action'......有没有办法将该路由器定义中的 :page 限制为仅整数,即如果我输入“/controller/2”,然后转到“controller/not-index”,页面= 2,如果我输入“/controller/other-action”,它实际上会转到“controller/other-action”

so I'm using zend_router to route my index page in my controller to an action other than the index action:

$route = new Zend_Controller_Router_Route(
                         '/controller/:page',
                          array(
                              'action' => 'not-index',
                              'controller' => 'controller',
                              'page' => 1,
                              ),
         );

And the reason why I'm adding :page into the path is because there's pagination in that index and I'd like to have paginator to work even if the user only enters '/controller' into the browser, so it's got to be there (see: http://www.joewebster.co.uk/articles/zend-framework/7-zend-pagination-and-zend-router)...

the problem is....now other actions within the controller will redirect to that page as well and not to the proper action

so suppose I enter '/controller/other-action' to the browser, it goes to 'controller/not-index' with page = other-action instead of 'controller/other-action' due to that routing definition....is there a way to limit the :page in that router definition to integers only, ie. if I enter '/controller/2' then go to 'controller/not-index' with page = 2, and if I enter '/controller/other-action' it'll actually go to 'controller/other-action'

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

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

发布评论

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

评论(1

薄凉少年不暖心 2024-12-21 04:18:12

我想你可能想看看 Regex_router:
http://framework.zend .com/manual/en/zend.controller.router.html#zend.controller.router.routes.regex

这应该可以帮助您实现目标。恐怕标准路由器不够灵活。

I think you might want to take a look at the Regex_router:
http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.regex

That should help you achieving your goal. I'm afraid the standard Router isn't flexible enough.

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