抛出下一个异常:Zend \ View \ Renderer \ PhpRenderer :: render:无法呈现模板“./opt/lampp/htdocs/guest-book/module/Records/view/records/records/paginator”;解析器无法解析为文件。我试图在不同的目录中设置不同的路径,但仍然不起作用
控制器:
class RecordsController extends AbstractActionController
{
protected $recordsTable;
public function indexAction()
{
$field = (string) $this->params()->fromRoute('field', 'date');
$order = (string) $this->params()->fromRoute('order', 'desc');
$array = array('records' =>$this->getRecordsTable()->getByOrder($field, $order),);
$paginator = new Paginator\Paginator(new Paginator\Adapter\ArrayAdapter($array));
$paginator->setCurrentPageNumber($this->params()->fromRoute('page', 1));
$paginator->setPageRange(3);
$paginator->setDefaultScrollingStyle('Sliding');
print_r($paginator);
$pag = new Helper\PaginationControl();
$pag::setDefaultViewPartial('opt/lampp/htdocs/guest-book/module/Records/view/records/records/paginator.phtml', 'default');
$vm = new ViewModel($array);
$vm->setVariable('paginator', $paginator);
return $vm;
}
RecordsTable:
class RecordsTable
{
protected $tableGateway;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function getByOrder($field, $order)
{
$this->field = $field;
$this->order = $order;
$resultSet = $this->tableGateway->select(function (Select $select) {
$select->order($this->field.' '.$this->order);
});
return $resultSet;
}
在视图中:
<?php if (count($this->paginator)): ?>
<ul>
<?php foreach ($this->paginator as $item): ?>
或只是:
<? echo $this->paginator;?>
还是个问题。
非常感谢!
答案 0 :(得分:2)
为什么在控制器中使用视图助手? git摆脱那个..
$pag = new Helper\PaginationControl();
$pag::setDefaultViewPartial('opt/lampp/htdocs/guest-book/module/Records/view/records/records/paginator.phtml', 'default');
在模板文件中正确使用它:
<?php echo $this->paginationControl($paginatior, 'Sliding', 'records/records/paginator.phtml') ?>