My Board
Creating the Model for CodeIgniter - Printable Version

+- My Board (https://ellohost.com/forum)
+-- Forum: Tutoriel EN (https://ellohost.com/forum/forumdisplay.php?fid=8)
+--- Forum: Others (https://ellohost.com/forum/forumdisplay.php?fid=20)
+--- Thread: Creating the Model for CodeIgniter (/showthread.php?tid=78)



Creating the Model for CodeIgniter - aaron - 07-20-2023


    Creating the Model for CodeIgniter
   

Creating the Model for CodeIgniter


   

Once the database table has been created, begin working on the business logic. To do this, create a model that will retrieve the database values.


   
           
  1. Access File Manager
  2.        

    Models are placed in the public_html/app/Models directory so they won't interfere with the application's directory structure. Go to the Models directory and create a new PHP file called AgencyModel.php.

           
  3. Paste the following code into the AgencyModel.php file:
  4.    
   
<?php namespace App\Models;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;
class AgencyModel extends Model
{
    protected $table = 'agencies';
    protected $allowedFields = ['name', 'email'];
}
   
   

As you can see, the model class (AgencyModel) extends the generic Model class that CodeIgniter provides. Note that CodeIgniter requires all class names to begin with a capital letter.