2010-09-27 71 views
0

是否有可能在$ _GET参数中使用paginator?

例如,我有这样的路线:

http://localhost/en/gallery?dep=9&cat=27&towns=1

但是,从结果中返回的链接是没有DEP:

$router->addRoute('ajax_gallery', 
new Routes_Categories(
'/:lang/:category/age/:dep/:cat/:towns', 
array(
"page" => 1, 
"dep" => 0, 
"cat" => 0, 
"towns" => 0 
), 
array(
"dep" => "[0-9]+", 
"cat" => "[0-9]+" 
) 

)); 

而且我通过AJAX请求作出这样的= 9 & cat = 27 & towns = 1

如何强制zend paginator使用传递的$ _GET pa内部分页链接代中的公羊?

使返回的链接是:

 
http://localhost/en/gallery/2?dep=9&cat=27&towns=1 
http://localhost/en/gallery/3?dep=9&cat=27&towns=1 
http://localhost/en/gallery/4?dep=9&cat=27&towns=1 

等等

甚至

 
http://localhost/en/gallery/2/9/27/1 
http://localhost/en/gallery/3/9/27/1 
http://localhost/en/gallery/4/9/27/1 

像他们里面路线 等定义...

谢谢

回答

1

视图URL助手将始终输出参数作为URL的一部分(用正斜杠分隔),并且,据我所知,不支持GET参数格式。

我不知道是什么Routes_Categories类完成,但是从默认工作ZF航线班试试这个:

$route = new Zend_Controller_Router_Route(
    '/:lang/:category/:age/:dep/:cat/:towns/*', 
    array(
     "dep" => 0, 
     "cat" => 0, 
     "towns" => 0 
    ), 
    array(
     "dep" => "[0-9]+", 
     "cat" => "[0-9]+" 
    ) 
); 
$router->addRoute('ajax_gallery', $route); 

的*支持任何额外名为PARAMS路线之后。以上假设需要lang,category和age,dep,cat和towns是可选的。请记住,如果你想设置猫,你必须设置dep,否则该路线会混淆哪个变量是什么。

在你的控制器通过访问以下,它通过AJAX套1

$page = $this->_getParam('page', 1); 

访问的URL默认为网页PARAM:http://localhost/en/gallery/2/9/27/1

如果你想在页面PARAM,使用命名参数:http://localhost/en/gallery/2/9/27/1/page/2

要使此路线在您的分页中工作,您需要更新Paginator视图控件以使用正确的路线。请参阅:http://framework.zend.com/manual/en/zend.paginator.usage.html#zend.paginator.usage.rendering.example-controls

查找输出URL的代码并将路由名称添加到URL视图助手。所以像这样的替换代码:

<?php echo $this->url(array('page' => $this->previous)); ?> 

有了:

<?php echo $this->url(array('page' => $this->previous), 'ajax_gallery'); ?>