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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:12:15+00:00 2026-05-26T23:12:15+00:00

The time has come for me to understand MVC, so that’s what I’m trying

  • 0

The time has come for me to understand MVC, so that’s what I’m trying to do; and I’m having trouble getting what a model is supposed to do. According to Wikipedia, a model:

The model manages the behaviour and data of the application domain,
responds to requests for information about its state (usually from the
view), and responds to instructions to change state (usually from the
controller). In event-driven systems, the model notifies observers
(usually views) when the information changes so that they can react.

And in CakePHP, you supposedly set up a model in this very simple way:

<?php

class Posts extends AppModel {
    var $name = 'Posts';
}

?>

So if I wanted, for example, the last 10 posts in my database, I would create a controller which would look something like this:

<?php

class PostsController {
    function retrieve_latest($number = 10) {
        $posts = $this->Users->find(array(
                'fields' => '*',
                'order' => 'posts.post_id DESC',
                'limit' => $number,
                'page' => '1',
                'conditions' => array('posts.post_display == 1')
        ));

        $this->set('posts', $posts);
    }
}

?>

And this guy would pass a variable called posts to my view, which would then render it accordingly. The thing is, isn’t my model supposed to do anything else?, because if its as simple as this, there would be no point for custom models at all, I mean, its just an empty extension to the model class.

  • 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-26T23:12:15+00:00Added an answer on May 26, 2026 at 11:12 pm

    This “empty extension to the model class” already does a lot of things: It hooks up to the database and does all the minute handling of retrieving and saving data. It is supposed to do a lot more though, including holding validation rules which are enforced anytime you’re writing to the database, any data massaging necessary in before/after filters and any other custom business logic you need in your application. Models are for storing your central business data logic, so anything that’s not presentation or input/output related but essentially models the core logic of your application. Just because the basics are simple to set up doesn’t mean there isn’t more to them.

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

Sidebar

Related Questions

I am having some trouble understanding the MVC Pattern. I do understand we are
This question has been puzzling me for a long time now. I come from
It is my first MVC project and always the first time has pain ;)
My android application needs to display time which has to be incremented according to
I've built apps that connect to a server. But this time a client has
I understand that this question has been asked multiple times, however I need further
I'm quite new to the on() method in jQuery but the time has come
I've come across a unit test that is failing intermittently because the time elapsed
I understand how to design a database schema that has simple one-to-many relationships between
Hi I' have come across to a code that I have hard time 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.