That seems incredibly inefficient, especially if each lookup is a round trip to the DB. Wouldn't you be better off creating a query that fetches both books and authors?
Cheers, David On 09/04/2013, at 11:42 PM, Matus Zeman <[email protected]> wrote: > Hi Sinimix, > I don't like to complicate the things by pre-loading models/entities as you > never know how "far" you're going to use them at the end - do I display the > author or not? etc etc... > We've got entity view helpers instead which I use as needed to retrieve > additional data/entities in view templates. Following MVC paradigm there > should not nothing wrong doing this as long as you read only from > models/services. > Our indexAction usually returns paginator (fully set up - like what page, > items per page, ...) of relevant entities and then we would just load > author entity if needed in the view template. > e.g. $author = $this->author()->find($book->getAuthorId()); > > Cheers, > Matus > > > On 9 April 2013 18:35, sinimix <[email protected]> wrote: > >> Robert, >> >> Thank you for the quick response (ili mozda da kazem hvala ;-) >> >> The problem is that I already implemented the logic you suggested, but it >> doesn't suit my current needs. Namely, I need to perform additional logic >> on >> results before I use them in the paginator. For example, in this particular >> case I need to set information about authors for every book in the >> resultset: >> >> ... >> public function getBooks($currentPage) >> { >> $select = new Select; >> $select->from('book'); >> >> $resultSet = $this->select($select); >> $resultSet->buffer(); >> $resultSet->next(); >> >> *foreach($resultSet as $book) { >> // Set author information for each book, e.g. >> $book->setAuthor($someAuthor); >> }* >> >> $iteratorAdapter = new Iterator($resultSet); >> $paginator = new Paginator($iteratorAdapter); >> $paginator->setItemCountPerPage(10); >> $paginator->setCurrentPageNumber($currentPage); >> >> return $paginator; >> } >> ... >> >> I'm not sure whether is it possible if the adapter is used directly in the >> paginator. >> >> Or maybe I missed something? >> >> >> >> -- >> View this message in context: >> http://zend-framework-community.634137.n4.nabble.com/ZF2-How-to-use-paginator-with-huge-number-of-records-tp4659675p4659677.html >> Sent from the Zend Framework mailing list archive at Nabble.com. >> >> -- >> List: [email protected] >> Info: http://framework.zend.com/archives >> Unsubscribe: [email protected] >> >> >> -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
