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.