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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:59:58+00:00 2026-06-09T06:59:58+00:00

I’m designing a web application with CodeIgniter (but I think the question applies generally

  • 0

I’m designing a web application with CodeIgniter (but I think the question applies generally to the MVC pattern in web applications).

When I design the model class for some database entity (say, a BlogEntry for illustration), I basically have two choices:

The “classic OOP” approach would be, to let the class represent the entity, i.e. one instance of the class is a BlogEntry. In CodeIgniter, this would lead to code like

class Blogentry extends CI_Model {
    function load($id) {
      // Access database
      $this->id = $dbresult.id;
      $this->title = $dbresult.title;
      $this->author = $dbresult.author;
    }
}

To get access to some blog entry, I would do a $this->load->model('blogentry');, call $this->blogentry->load($id) and then work with the model class instance.

The other approach, which I’ve seen frequently in the wild, is to let the model return the entity in some data structure. In code:

class Blogentry extends CI_Model {
  function get_entry($id) {
    // Access database, yielding $dbresult
    return $dbresult;
}

With this I would write

$this->load->model('blogentry');
$the_entry = $this->blogentry->get_entry($id);

in the controller and work with $the_entry. In this second case, the class is more like a factory or builder class.

Is any of these two approaches considered the “right way” of doing M in MVC? I think, I’ve seen the second approach more often, but I didn’t look at that many MVC-Webapps. Any thoughts of why the first or the second approach might be more appropriate?

  • 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-06-09T07:00:00+00:00Added an answer on June 9, 2026 at 7:00 am

    First and foremost, CodeIgniter is not an MVC framework. The paradigm that fits best is probably MVP or something like ORM-Template-Adapter. So let me break down my answer based on that naming fallacy:

    In Classical/traditional MVC (not what frameworks claim is MVC), a model is not a class or a single file, but rather a layer that contains all of the domain business logic, and usually are only made of of things like Domain Objects, Data Mappers, and something to handle the interface between the calling entity and the domain logic, as to keep such code out of the controller (in MVC, for example). Tereško names them “services”, which is good enough for a quasi-official name.

    So in traditional MVC, requests to the model layer com in through “services,” which in turn interact with the domain objects and data mappers.

    Obviously all of that has little relevance to what CodeIgniter and other frameworks call “MVC.” In this design pattern (I’ll call it “CIMVC” for short), a Model is a class that is called and manipulated by the Controller, and interacts with the database directly. Storing data in member variables within the model doesn’t make a whole lot of semantic sense, but if you’re interested in something similar, check out any of the ORM plugins/libraries written in CIMVC. (Though ORM solutions wouldn’t be any better at conforming to traditional MVC…)

    As for common practices, most of the CI applications I’ve seen return “raw” database data back to the controller for handling; This keeps the domain business logic within the model. My personal preference in CIMVC is to minimize/eliminate anything but domain business logic in the models.

    tl;dr – “Traditional/proper” MVC in CodeIgniter is basically impossible, so trying to force your CI code to conform to traditional MVC paradigms is silly (and will likely drive you to insanity)

    edit: To clarify some earlier confusion about business logic in the Model layer, yes, you should have all of the business logic in the model layer. However if there is extra data processing going on (sorting, manipulation, etc), now we move into dangerous territory for DRY and SRP violations; You want the model to be reusable, so be wary of adding so much or such specialized logic that it becomes unusable in other parts of the application.

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I want to construct a data frame in an Rcpp function, but when I

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.