Creating a PHP website using MVC – 4 Creating Model class

The Model class we create is the base class for all Models and it contains some common functions like getAll(), getOne(), getById(), search(), count() etc. These static methods will also be available for all other Models extending the base Model class. The model creates instances of itself for each result item for the query. i.e., if we call Book::getAll() we will get an array consisting of Book instances.

We might need to define item specific methods and properties into the classes though. In any of the inherited model classes don’t need to call any database calls directly. The model base class does this behind. When we call the method save() on an instance, it will get updated in the database and if it is not found in the database an entry is created.
Continue reading