Zend Framework 视图脚本不包含父类的变量

问题描述 投票:0回答:1

我为多个控制器创建了一个父 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();             
    }

}
php view zend-framework
1个回答
0
投票

你使用

$this->getView()->paginator = $this->getPaginator();

应该是

$this->view->paginator = $this->getPaginator();
© www.soinside.com 2019 - 2024. All rights reserved.