检测 zend router 变量中的变量类型
所以我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你可能想看看 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.