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 867605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:00:15+00:00 2026-05-15T10:00:15+00:00

I use rich domain model in my app. The basic ideas were taken there

  • 0

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.

  • 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-15T10:00:16+00:00Added an answer on May 15, 2026 at 10:00 am

    Here is my solution:

    class Model_Mapper_Db_Comment extends Model_Mapper_Db_Abstract {
    
        public function getUserCommentsPaginator($user_id) {
            $select = $this->_getTable()->select()->where('user_id = ?', (int)$user_id);
            $paginator = Zend_Paginator::factory($select, 'DbSelect');
            return $paginator;
        }
    } 
    
    class Model_User extends Model_Abstract implements Zend_Auth_Adapter_Interface {
    
        public function getCommentsPaginator() {
            $paginator = $this->getMapper(null, 'Comment')->getUserCommentsPaginator($this->id);
            $paginator->setFilter(new App_Filter_Array_Collection('Model_Collection_Comments'));
            return $paginator;
        }
    }
    

    Model requests Zend_Paginate object with prepared query based on user_id provided from Model. Then Model added filter to Zend_Paginate object to make it compatible with other Model methods (return Model_Collection classes, not arrays). All other pagination parameters are set in controller (page, the number of items per page, etc.).

    Thet’s how I had separated storage, business and control logic in my application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Spring MVC application trying to use a rich domain model, with
Is it possible to use DDD and a rich domain model if your application
I've got a rich domain model, where most classes have some behaviour and some
Use Case When a user goes to my website, they will be confronted with
For a rich domain driven design I want to use Guice dependency injection on
i have a java applet application in which i use rich text area .
I am evaluating Rich Internet application solutions to use in next project. I have
How does one use a rich web text editor in coldfusion? is there any
is it possible in Wordpress to have the category description use a rich text
Is there any way I can use to bind Rich Text Format (RTF) data

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.