【发布时间】: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