The CI model provides services for all the application modules to access the application database(s) or external information resources in an OOP fashion. Typically, the model classes will contain functions that help us retrieve, insert, and update information in the database.
This section will focus on the CI model syntax and usage guidelines, as a preface to the following usage code examples.
The model files are located in the folder application/models/
, in the pattern application/models/<MODEL_NAME>.php
.
Loading a model can be done automatically or via the controller. More specifically, it can be done in a certain controller's constructor or any controller's method.
If the model is used in a few of the controller's methods, it's recommended that you load the model in those methods. The scope of the model in that case is only in those methods project and will refer to
application/models/mymodel.php
.If the model is used in most...