2008年12月8日星期一

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

class News
{
    public function findAllForPage($page)
    {
        // ...
        return $paginator;
    }
}

class NewsController
{
    public function indexAction()
    {
        $news = new News();
        $paginator = $news->findAllForPage($this->_getParam('page'));
        $paginator->setItemCountPerPage(3);
        // etc.
        $this->view->paginator = $paginator;
    }
}

-Matt

On Mon, Dec 8, 2008 at 12:26 AM, vladimirn <nezaboravi@gmail.com> wrote:

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--tp20890711p20890711.html
Sent from the Zend DB mailing list archive at Nabble.com.


没有评论: