I have been playing with doctrine2 + ZF setup for the last couple of days.
One of the things I still can't figure out is the large array collection assosicaitons. For example let's say we have an entity called Post and each post can have many comments.
<?php
/**
* @Entity
*/
class Post
{
/**
* @OneToMany(targetEntity="Comment", mappedBy="post")
*/
protected $comments;
}
?>
Now this will load all comments if I do
$post->comments
But what if there are, say 10000 comments for this particular post? Then all will be loaded which is not good. And as far as I know slice/pagination will not be available until doctrine 2.1.
Can someone advice me how I can paginate comments? With DQL maybe? if DQL, where do you implement this?Do I create a getComments method in the Post entity and do the DQL there?
Thanks Bill
Doctrine 2.2 now has a Paginator class. See this link for how to use it with Zend_Framework: Reply to How to use D2's Paginator with Zend_Paginator
I'm using pagination from https://github.com/beberlei/DoctrineExtensions, it works great, at least for me.
Edit: Not sure this will help you, but here's how I did my pagination
Controller
View
pagination.html
You may consider implementing
Zend_Paginator_Adapter_Interface
.See ZF docs for more details: