Zend framework2 ZF2-在分页中使用url帮助器从表单保留查询
我是ZF2新手,我愿意与大家分享如何使用url帮助器从表单中保留参数,特别是在分页期间。我从中修改了答案 我就是这么做的: AlbumController.phpZend framework2 ZF2-在分页中使用url帮助器从表单保留查询,zend-framework2,Zend Framework2,我是ZF2新手,我愿意与大家分享如何使用url帮助器从表单中保留参数,特别是在分页期间。我从中修改了答案 我就是这么做的: AlbumController.php // get all the query from url $input = $form->getData(); $paginator = $this->getAlbumTable()->fetchAll(); $paginator->setCurrentPageNumber((int)$this->p
// get all the query from url
$input = $form->getData();
$paginator = $this->getAlbumTable()->fetchAll();
$paginator->setCurrentPageNumber((int)$this->params()->fromQuery('page', 1));
$paginator->setItemCountPerPage(30);
// unset the 'page' query if necessary
unset($input['page']);
return array(
'form' => $form,
'paginator' => $paginator,
'routeParams' => array_filter($input) // filter empty value
);
index.phtml
echo $this->paginationControl(
$this->paginator,
'sliding',
array('partial/paginator.phtml', 'Album'),
array(
'route' => 'album',
'routeParams' => $routeParams
)
);
<a href="<?php echo $this->url(
$this->route, // your route name
array(), // any url options, e.g action
array('query' => $this->routeParams) // your query params
);
echo (empty($this->routeParams))? '?' : '&'; ?>
page=<?php echo $this->next; ?>">Next Page</a>
paginator.phtml
echo $this->paginationControl(
$this->paginator,
'sliding',
array('partial/paginator.phtml', 'Album'),
array(
'route' => 'album',
'routeParams' => $routeParams
)
);
<a href="<?php echo $this->url(
$this->route, // your route name
array(), // any url options, e.g action
array('query' => $this->routeParams) // your query params
);
echo (empty($this->routeParams))? '?' : '&'; ?>
page=<?php echo $this->next; ?>">Next Page</a>
请提供更好的解决方案,如果我错了请纠正我
谢谢你我没有比你更好的解决方案-我看不到在添加新的查询参数时保留现有查询参数的正确方法。但以下内容比手动添加&and=字符更简洁: paginator.phtml
这也将确保如果您已经有一个页面
参数,它将被新的页面覆盖
(从技术上讲,您也可以直接使用$\u GET
或$\u POST
并避免从控制器传递它,但这似乎不是很整洁)