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

  • Home
  • SEARCH
  • 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 6031705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:13:29+00:00 2026-05-23T05:13:29+00:00

I am currently trying to figure out how to properly implement the the MVC

  • 0

I am currently trying to figure out how to properly implement the the MVC principle. Lets take for example a simple blog. I have a database that contains two tables: Blogs and comments. The blogs table consists of fields like a title, content, date, etc. Comments contain an autorname, a date, content, stuff like that.

Lets start with the easier items. I have a couple of views. Like:

  • Write / edit blog item
  • Display a blog item
  • Display a summary page (e.g. recent blogs, popular topics, etc)
  • etc

The controllers are also quite clear to me:

  • Admin controller (transfers blog items to the write / edit views or sends them back)
  • Blog controller (transfers blog items to the blog views, like the summary page or the page where just one is displayed. This also retrieves the comments)
  • Comment controller (transfers data from the comment creation / deletion views)

But then comes the models. I really don’t know how I should implement these. The Zend Framework quickstart page recommends a pretty small model with only private properties and getters and setters for the specific item. They recommend doing the database logic in a Mapper.

But here’s my question. Let’s say I want to fetch the most recent blog items. How would you implement this? Where would you write the function fetchRecentItems()? In the mapper? It seems that this should contain only basic CRUD statements. In another model, like BlogService? In the controller?

Can someone help me out here? I would love to see a quick pseudo-code example.

(I tried to summarize my knowledge to make my thinking process a little bit more clear. If I understood something wrong, please correct me. Thanks!)

  • 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-23T05:13:30+00:00Added an answer on May 23, 2026 at 5:13 am

    It depends how far you want to go with it really. Personally I would use a Service class, interacting with mapper classes, called from the controller. So your class might look something like:

    class Yourapp_Service_Blog
    {
        protected $_mapper;
    
        public function setMapper($mapper)
        {
            $this->_mapper = $mapper; 
    
            return $this;
        }
    
        public function getMapper()
        {
            return $this->_mapper;
        }
    
        public function fetchRecentItems($items)
        {
            $select = $this->getMapper()->getDbTable()->select();
            $select->order('createdAt DESC')
                   ->limit($numItems);
    
            return $this->getMapper()->fetchAll($select);
        }
    }
    

    so then in your controller:

    class BlogController extends Zend_Controller_Action
    {
        public function indexAction()
        {
            $service = new Yourapp_Service_Blog();
            $service->setMapper(new Yourapp_Model_GuestbookMapper());
    
            $this->view->posts = $service->fetchRecentItems(6);
        }
    }
    

    this starts to look like a lot of code to do a simple thing, but when you start seeing common elements between the classes you can refactor a bit to improve things. E.g. if you have multiple service classes that look like this you can move the get/set mapper functions into a base service class that they extend. You could add some logic to the getMapper() function that would work out what the correct mapper is based on the class name if one hasn’t been supplied, saving you having to pass it in each time.

    There isn’t a ‘right’ answer here though, these patterns exist as solutions to common programming problems. Use as many or as few of them as you feel is appropriate for your app.

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

Sidebar

Related Questions

I'm trying to figure out where to properly set tableView.rowHeight. Currently I have it
I have been trying to figure out how to properly use scopes for the
I am currently trying to figure out how you can bind multiple fields in
Hey, I'm trying to figure out how to display the ▼ character properly in
I am currently trying to figure out how to connect to another server via
My partner, the designer, and I, the developer, are currently trying to figure out
I am trying to figure out whether or not the current date falls within
I'm trying to figure out how to detect when the current user has changed
I'm trying to figure out how to use Zend_Db_Table_Abstract correctly. I want to return
I'm trying to figure out if I should continue on with a current pattern

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.