我需要在我的控制器中使用一个分页控件助手来返回JsonModel,而不是简单的视图。
这是代码
$paginationHelper = new \Zend\View\Helper\PaginationControl();
$paginationHelper->setView(new PhpRenderer());
$paginationTxt = $paginationHelper(
$pagination,
'Sliding',
array('user/user/pagination', 'User'),
array('route' => 'user', 'action' => $action)
);
$ pagination是Zend \ Paginator \ Paginator的实例
错误是
No paginator instance provided or incorrect type
如果我把代码放在视图中就可以正常工作
EDIT1:
我试过
$view = new PhpRenderer();
$view->paginationControl($pagination,
'Sliding',
array('user/user/pagination', 'User'),
array('route' => 'user', 'action' => $action));
相同的结果
我以这种方式更改代码
$ paginationHelper-> setDefaultViewPartial( 'pagination.phtml');
$paginationTxt = $paginationHelper($pagination,
'Sliding',
null,
array('route' => 'user', 'action' => $action));
一切正常
答案 0 :(得分:1)
使用ViewHelperManager
获取它$viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
$paginationHelper = $viewHelperManager->get('paginationControl');