我在我的示例应用程序中实现 DAO 模式,我有一个包含从 UserMapper 获取的用户(域)的普通数组这样做是因为它违背了 DAO 的目的。
下面的示例代码(不工作)
$userMapper = new Application_Model_UserMapper();
$users = $userMapper->getUsers();
$paginator = Zend_Paginator::factory($users);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(1);
$this->view->paginator = $paginator;
下面的示例代码(工作)
$users = new Application_Model_DbTable_User();
$select = $users->fetchAll();
$paginator = Zend_Paginator::factory($select);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(1);
$this->view->paginator = $paginator;