添加userid参数以在ZF分页中路由配置

时间:2017-10-18 22:28:40

标签: routes zend-framework2 zend-framework3

到目前为止,这是我的代码:

<?php 
echo $this->paginationControl($this->paginator,'sliding','partial/paginator.phtml',array('route' => 'adminuserlog'));
?>

我的错误是:

Missing parameter "userid"

如何将userid param附加到呼叫的路由部分?用户ID的值为$this->user->getId()

1 个答案:

答案 0 :(得分:0)

PaginationControl viewHelper的最后一个参数是将数据传递到分页部分/视图的方式。

echo $this->paginationControl(
    $this->paginator,
    'sliding',
    'partial/paginator.phtml',
    array(
        'route' => 'adminuserlog',
        'routeParams' => array('userId' => $this->user->getId())
    ),
);

由于partial/paginator.phtml只是一个视图,我们可以使用$route$this->route来访问任何视图变量。

更新您的partial/paginator.phtml文件以包含$routeParams

$routeParams = isset($this->routeParams) && is_array($this->routeParams) ? $this->routeParams : [];
$queryParams = isset($this->queryParams) && is_array($this->queryParams) ? $this->queryParams : [];

$urlOptions = ['query' => $queryParams];

// Rendering a button and usage of the URL viewhelper
<a href="<?= $this->url(
    $route,
    $routeParams,
    ArrayUtils::merge($urlOptions, ['query' => ['page' => $this->first]])
); ?>">
    <span aria-hidden="true">&laquo;</span>
</a>