2008年12月23日星期二

RE: [fw-db] Zend Pagination within Model-how to?

Hi,

Found some "official" examples of pagination for you.

http://framework.zend.com/wiki/display/ZFPROP/Zend_Paginator+-+Matthew+Ratzl
off


Regards


-----Original Message-----
From: vladimirn [mailto:nezaboravi@gmail.com]
Sent: Monday, December 08, 2008 10:26 AM
To: fw-db@lists.zend.com
Subject: [fw-db] Zend Pagination within Model-how to?


Finnaly i thought that something will go smoothly with ZF and me :)
Alas!
I have my news model- news.php
I would like to list all news, limit 10 adn want to show pagination on the
view script.
And, i have this already done in my other controller, but now i want to
separate models from controllers, and all went nice and smooth, but
pagination.
My comments are CAPSED bellow ::)
***********************************************
public function getAllNews(){
$select = $this->db->select()->from('news', array (
"DATE_FORMAT(posted, '%m/%d/%Y') AS date" , 'news' , 'newsid' ,
'postedby' ,'display','area'
))->order('posted','DESC');
//BTW, THIS 'ORDER('posted','DESC') WONT WORK! News are listed on the same
way whatever i put in order conddition? I'v tried to change to newsid, desc
or newsid, asc, no changes...
$paginator = Zend_Paginator::factory($select);
// Set parameters for paginator
$paginator->setCurrentPageNumber($this->_getParam("page"));//THERE
IS AN ERROR!!! Fatal error: Call to undefined method AdminNews::_getParam()
in D:\wamp\www\singlescash\application\admin\models\AdminNews.php on line 35

//ok i know why is that error here, but how to avoid it??
$paginator->setItemCountPerPage(3);
$paginator->setPageRange(5);
$this->view->paginator = $paginator;// ALSO I AM AWARE THAT I CANT
SET VIEW FROM MODEL?
// $select = ("SELECT DATE_FORMAT(posted, '%m/%d/%Y') AS date, news,
newsid,postedby,display, area FROM news ORDER BY posted DESC, newsid DESC");
return $this->db->fetchAll($select);
}
************************************************
How to combine all this and get pagination to work when i am using model adn
my query is in model, not in the controller?
thanks,
V
--
View this message in context:
http://www.nabble.com/Zend-Pagination-within-Model-how-to--tp20890711p208907
11.html

Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: