Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3801930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:07:39+00:00 2026-05-19T14:07:39+00:00

I have been playing with doctrine2 + ZF setup for the last couple of

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:07:40+00:00Added an answer on May 19, 2026 at 2:07 pm

    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

    // Create the query
    $qb = $this->_em->createQueryBuilder();
    
    $qb->select('p')
       ->from('Identiti_Entities_Pengguna', 'p');
    
    // Sorting
    $qb->addOrderBy('p.' . $input->sort, $input->dir);
    
    $q = $qb->getQuery();
    
    // Pagination
    $itemPerPage = 100;
    
    $records = new Zend_Paginator(
                    new DoctrineExtensions\Paginate\PaginationAdapter($q));
    
    $records->setCurrentPageNumber($input->page)
            ->setItemCountPerPage($itemPerPage)
            ->setPageRange(10);
    
    $this->view->records = $records;
    

    View

    <?
    echo $this->paginationControl($this->records,
                                  'Sliding',
                                  'partials/pagination.phtml');
    ?>
    

    pagination.html

    <?php if ($this->pageCount): ?>
    <ul id="pagination-digg">
        <li class="previous"><a href="#">Pages: <?=$this->pageCount?></a></li>
    <!-- Previous page link -->
    <?php if (isset($this->previous)): ?>
      <li class="previous"><a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
        &lt; Previous
      </a></li>
    <?php else: ?>
        <li class="previous-off">&lt; Previous</li>
    <?php endif; ?>
    
    
    <!-- Numbered page links -->
    <?php foreach ($this->pagesInRange as $page): ?>
        <?php if ($page != $this->current): ?>
            <li>
                <a href="<?php echo $this->url(array('page' => $page)); ?>">
                    <?php echo $page; ?>
                </a>
            </li>
        <?php else: ?>
            <li class="active"><?php echo $page; ?></li>
        <?php endif; ?>
    <?php endforeach; ?>
    
    <!-- Next page link -->
    <?php if (isset($this->next)): ?>
        <li class="next">
            <a href="<?php echo $this->url(array('page' => $this->next)); ?>">
                Next &gt;
            </a>
        </li>
    <?php else: ?>
      <li class="next-off">Next &gt;</li>
    <?php endif; ?>
    </ul>
    <?php endif; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been playing around with JMX for the last few days and although
I have been playing around with GTK since a couple of days now,while going
I have been playing around with silverlight for a couple of days now and
I have been playing around with the postgresql.conf file for a couple days now.
I have been playing with Yii for a couple of months now, and to
I have been playing with Expect/TCL today and I was hoping someone can tell
I have been playing around with the MVP pattern using winforms for the last
I have been playing around with in app purchases for a few days, everything
I have been playing with Facebook Graph API around a week, and I still
I have been playing around with this problem since yesterday. I can't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.