$paginator = Zend_Paginator::factory($select);
$select has to be an instance of Zend_Db_Select
Build your query with Zend_Db_Select and it shoud work
$select = $this->db->select()
->from(array('a' => 'banners '), array('*'))
->where('active = ?', 'y')
->where('programid = ?', $programid)
->where('websiteid = ?', $websiteid)
->where('bannertype = ?', $bannertype )
;
If i am doing this:
$sql = "select * from banners where active='y' and programid='" .
$programid . "' and websiteid = '" . $websiteid . "' and bannertype= '"
. $bannertype . "'"; //$result = $db->fetchAll ( $sql );
$paginator = Zend_Paginator::factory($sql);
i am getting an error:
Vladimir Nikolic schrieb:
Daniel Tangermann wrote:
Try not to pass the total $result array. Let paginator execute the
query.
$paginator = Zend_Paginator::factory($select);
$paginator->setItemCountPerPage(10);
$paginator->setCurrentPageNumber($page);
$paginator->setPageRange(10);
$paginator->setDefaultScrollingStyle('Sliding');
Zend_View_Helper_PaginationControl::setDefaultViewPartial('paginator.phtml');
$this->view->pages = $paginator->getPages();
This case you only query for the element needing (limit,offset).
When linking make certain that you catch the selected like
$page = $this->_request->getParam('page')
Works fine for me
vladimirn schrieb:
I have a problem with zend pagination.
In my controller i have this:
$result = $db->fetchAll ( $sql );
$page = $this->_getParam ( 'page', 1 );
$paginator = Zend_Paginator::factory ( $result );
$paginator->setItemCountPerPage ( 2 );
$paginator->setCurrentPageNumber ( $page );
$paginator->setPageRange ( 5 );
Zend_View_Helper_PaginationControl::setDefaultViewPartial (
'paginator.phtml' );
$this->view->paginator = $paginator;
Now in my view file i am getting this:
Start | < Previous | 1 2 3 | Next > | End Page 1 of 3
Page 2 and 3 and Next are links, but when i click on them, my browser
reload, but same result is display on the page. Actually i am not
getting
result for page 2, 3 or next. Same result as for page 1 is
displayed. How to
fix this?
Thanks,
V
Hello Daniel,
How you build your sql query in this case?
If i am doing this:
$sql = "select * from banners where active='y' and programid='" .
$programid . "' and websiteid = '" . $websiteid . "' and bannertype=
'" . $bannertype . "'"; //$result = $db->fetchAll ( $sql );
$paginator = Zend_Paginator::factory($sql);
i am getting an error:
Error!
Application error
Exception information:
*Message:* No adapter for type string
Stack trace:
#0
D:\wamp\www\singlescash\application\controllers\BannersController.php(58):
Zend_Paginator::factory('select * from b...')
#1 D:\wamp\www\singlescash\library\Zend\Controller\Action.php(502):
BannersController->displayAction()
#2
D:\wamp\www\singlescash\library\Zend\Controller\Dispatcher\Standard.php(293):
Zend_Controller_Action->dispatch('displayAction')
#3 D:\wamp\www\singlescash\library\Zend\Controller\Front.php(946):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http))
#4 D:\wamp\www\singlescash\application\bootstrap.php(168):
Zend_Controller_Front->dispatch()
#5 D:\wamp\www\singlescash\index.php(2):
require_once('D:\wamp\www\sin...')
#6 {main}
Thanks,
V