#21 Models in CodeIgniter 4 | How to load a model into a Controller

Опубликовано: 29 Сентябрь 2024
на канале: GoPHP
13,440
100

What is a Model?
A Model is nothing but a PHP class file, which contains collection of methods to interact with a specific table in your database.

We know that, As per MVC, a Model will always communicate with our DB. Model is Responsible to get data from database.

Models are typically stored in the app/Models directory
Every model class should be under the namespace called: namespace App\Models.
CI4 is providing helper methods to work with database.

We can access models within our Controller by creating an instance of a model class
$userModel = new \App\Models\UserModel();