2009/2/10 PHPScriptor <[email protected]>:
>
> I don't know if this will answer your question, but this is how I do it:
>
> The paginator is set in the controller. I think you could do it in the
> model, but that would make things a lot complicater.
> Where to define your select, where,... 99% I do in the controller. 'Cause if
> not, you need to pass all your values to the model. But the joins I always
> do in the model (don't even think they would work in the controller). Let me
> explain with a little example:
>
> $NewsModel = new News_NewsModel();
> $select = $NewsModel->select();
> $select->order('newsdate DESC');
> $select->where('id>5');
> $news = $NewsModel->fetchAll($select)->toArray();
But doesn't this mean that if I have let's say 12 000 rows in my
table, I have to fetch all of them just to display a very little part.
That's big overkill I think. The table I have in mind gets around 100
new records each day. What happens when the records count becomes say
200 000?
> $paginator = Zend_Paginator::factory($news);
> $paginator->setCurrentPageNumber($this->_getParam('page'));
> $paginator->setItemCountPerPage(5);
> $paginator->setPageRange(10);
>
> $this->view->news = $paginator;
>
> The 'order' and 'where' can also be done in a model-function. But why
> creating an extra function just for 2 conditions. So I do it in my
> controller.
> Let me extend this example with a model and a join.
>
> class News_NewsModel extends Zend_Db_Table_Abstract
> {
> protected $_name = 'news_news';
> protected $_primary = array('id');
>
> public function fetchAll($select=null) {
> if(is_null($select))
> $select = parent::select();
>
> $select->setIntegrityCheck(false);
>
> $select->from($this->_name,array('*'))
> ->joinLeft('tbl_test,
> 'tbl_test.id=news_news.test_id',
> array('field'));
>
> $results = parent::fetchAll($select);
> return $results;
> }
> }
>
> The adventage of this way ("where" and "order" in controller) is that you
> could use the fetchAll more then ones in other controllers. And just make
> other conditions in those controller and use the same model-function
> fetchAll.
>
> I hoped this helped...
>
>
> Deepak Shrestha wrote:
>>
>> Hi,
>>
>> Short and quick question:
>> ========================
>> I need some background and hint on how to use Paginator in strict Zend
>> Framework MVC convention? (no customization) also some insight on
>> "Zend_Controller_Router_Interface". I cannot find enough information
>> in documentation to grasp this.
>> ========================
>>
>> Long Question:
>> =========================
>> Currently my implementation is like this (for inserting updating data):
>>
>> Controller -> Model -> DBTable
>>
>> Now I am trying to implement search part and found out about
>> Paginator, which is a cool thing to implement for lots of results. I
>> need some hint on how to implement this in my current implementation
>> (staying strictly within the ZF MVC convention)? I need some overview
>> on where things get initialized plus how data is accessed etc.
>>
>> Actually based on what I am going to implement, I guess I need to
>> manipulate the 'Select' in my controller (which changes based on
>> user's criteria) but currently I am delegating dirty works to Model.
>> If I delegate this to model then where do I initialize the Paginator
>> and feed the Select? etc. Sorry currently my view on Paginator is
>> still blurred and I don't know if I am asking the right question.
>>
>>
>> Thanks
>>
>>
>> --
>> =======================
>> Registered Linux User #460714
>> Currently Using Fedora 8, 10
>> =======================
>>
>>
>
>
> -----
> visit my website at http://www.phpscriptor.com/ http://www.phpscriptor.com/
> --
> View this message in context:
> http://www.nabble.com/Zend_Paginator-Question-tp21931445p21931824.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>
--
Regards,
Martin Martinov
http://mmartinov.com/