Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating the Model for CodeIgniter
#1

    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.


   


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)