我为多个控制器创建了一个父 CRUD 类,当我渲染脚本时,它无法识别我在 listAction() 中设置的分页器变量。该代码来自我的父类。例如,我扩展
Admin_UserController
以创建 Webapp_Controller_Crud
。
class Webapp_Controller_Crud extends Zend_Controller_Action
{
public function init()
{
$actionController = get_class($this);
$actionController = str_replace('Admin_',null,$actionController);
$actionController = str_replace('Controller',null,$actionController);
$this->_actionClassName = $actionController;
$actionController = 'Model_' . $this->_actionClassName;
$this->_actionModel = new $actionController();
}
/**
* @return Zend_Paginator
*/
public function getPaginator()
{
$model = $this->getActionModel();
$adapter = new Zend_Paginator_Adapter_DbSelect($model->select());
$paginator = new Zend_Paginator($adapter);
$paginator->setItemCountPerPage(10);
$page = $this->_request->getParam('page', 1);
$paginator->setCurrentPageNumber($page);
return $paginator;
}
public function listAction()
{
$this->view->paginator = $this->getPaginator();
}
}
你使用
$this->getView()->paginator = $this->getPaginator();
应该是
$this->view->paginator = $this->getPaginator();