【问题标题】:detecting variable type in zend router variables在zend路由器变量中检测变量类型
【发布时间】:2012-09-12 20:30:49
【问题描述】:

所以我使用 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”,由于该路由定义,它会使用 page = other-action 而不是“controller/other-action”进入“controller/not-index”。 ...有没有办法将该路由器定义中的 :page 限制为仅整数,即。如果我输入 '/controller/2' 然后转到 'controller/not-index' 页面 = 2,如果我输入 '/controller/other-action' 它实际上会转到 'controller/other-action'

【问题讨论】:

  • 要使page 参数验证为整数,您必须在路由中添加第三个数组参数:array('page' => '^\d+$')。此外,Router_Route 最接近的方法是将路由字符串更改为/controller/:action/:page,但controller/2 仍然无法按预期工作。正如@maraspin 所说,您需要正则表达式。

标签: php model-view-controller zend-framework url


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2015-12-26
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多