Pagination in a Rich Domain Model

Posted by user246790 on Stack Overflow See other posts from Stack Overflow or by user246790
Published on 2010-05-21T16:42:34Z Indexed on 2010/05/22 9:20 UTC
Read the original article Hit count: 244

I use rich domain model in my app. The basic ideas were taken there. For example I have User and Comment entities. They are defined as following:

<?php
class Model_User extends Model_Abstract {

    public function getComments() {
        /**
        * @var Model_Mapper_Db_Comment
        */
        $mapper = $this->getMapper();
        $commentsBlob = $mapper->getUserComments($this->getId());
        return new Model_Collection_Comments($commentsBlob);
    }

}

class Model_Mapper_Db_Comment extends Model_Mapper_Db_Abstract {

    const TABLE_NAME = 'comments';

    protected $_mapperTableName = self::TABLE_NAME;

    public function getUserComments($user_id) {
        $commentsBlob = $this->_getTable()->fetchAllByUserId((int)$user_id);
        return $commentsBlob->toArray();
    }
}

class Model_Comment extends Model_Abstract {

}
?>

Mapper's getUserComments function simply returns something like:

return $this->getTable->fetchAllByUserId($user_id)

which is array. fetchAllByUserId accepts $count and $offset params, but I don't know to pass them from my Controller to this function through model without rewriting all the model code.

So the question is how can I organize pagination through model data (getComments). Is there a "beatiful" method to get comments from 5 to 10, not all, as getComments returns by default.

© Stack Overflow or respective owner

Related posts about zend-framework

Related posts about model