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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:51:39+00:00 2026-06-10T12:51:39+00:00

Recently I have started working with Codeigniter framework in order to develop RESTFul web

  • 0

Recently I have started working with Codeigniter framework in order to develop RESTFul web service for mobile application.

As I was looking at various tutorials on web sites and on youtube, I found that the concept of a Model is being used differently in PHP application context.

How differently?

Well, as I always thought Model classes should look like,

Cat.php

<?php

class Cat {
   
   // Class variables
   private $colour;
   
   public __construct() {
      $colour = 'Brown';
   }

   // Getters and Setters

   public function getColour() {
      return $this->colour;
   }

   public function setColour($newColour) {
      $this->colour = $newColour;
   }

}

?>

but, while searching for good tutorials over the internet I found that people are just using functions that has access to the database for data and returning it to Controller.

I haven’t seen any one writing normal classes in Model (If you are Java person then, we call it POJO)


Now, What I entailed after reading and watching these tutorials that,

In context of PHP application frameworks, The Model classes are connectors to the database which returns the application related data upon query. In language of SQL people we call it,

  • CRUD functions

    • Create
    • Read
    • Update
    • Delete

So, correct me if I am wrong.

In web application created by taking base of Codeigniter like framework, where the MVC pattern is used to design an application. The Model classes are the one which will have functions that connects application to the database and returns the data, as well as helps to perform all CRUD operations on application’s database.

  • 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-10T12:51:41+00:00Added an answer on June 10, 2026 at 12:51 pm

    Well, if you have used C# or Ruby, there you can find a good way to apply the MVC pattern. In PHP, in my opinion, people sometimes are confused about the terms. The way I use the MVC pattern in PHP is like the following:

    CONTROLLER

    class UserController { 
    
        private $repo;
    
        public function __construct() { 
            $this->repo = new UserRepository(); // The file which communicates with the db. 
        }
    
        // GET
        // user/register
        public function register() { 
            // Retrieve the temporary sessions here. (Look at create function to understand better)
            include $view_path;
        }
    
        // POST
        // user/create
        public function create() { 
            $user = new User($_POST['user']); // Obviously, escape and validate $_POST;
            if ($user->validate())
                $this->repo->save($user); // Insert into database
    
            // Then here I create a temporary session and store both the user and errors.
            // Then I redirect to register
        }
    
    }
    

    MODEL

    class User { 
    
        public $id;
        public $email;
    
        public function __construct($user = false) {
            if (is_array($user))
                foreach($user as $k => $v) 
                    $this->$$k = $v;
        } 
    
        public function validate() { 
            // Validate your variables here
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started working on a web application at a new company and
I have recently started working on a legacy application that has most of its
This is a very elementary I realize, I have recently started working with asp.net
I have recently started using RSpec for Integration testing in my Rails application, to
I have recently started working on an app which has both Java and native
I have recently started working on my master thesis in C that I haven't
I have recently started working in iOS Development, I have noticed the app size
I've started working with SSAS cubes recently. I have a requirement where I need
I have a project that I have recently started working on seriously but had
I have started working with C++ recently and am not comfortable with Visual Studio

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.