phpviewzend-framework

Zend Framework view script not containing variables from parent class


I created a parent CRUD class for several controllers and when I render the script it isn't recognizing the paginator variable I set within the listAction(). The code is from my parent class. For instance, I extend Admin_UserController to create 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();             
    }

}

Solution

  • You use

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

    Which should be

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