Codeigniter Autoload Models


Codeigniter autoload models: You can auto-load models instead of loading it again and again.


Syntax : Codeigniter autoload models

1. Go to application/config/autoload.php
2. Go to the below lines

$autoload['model'] = array();

3. Now Add your model you want to auto-load.

$autoload['model'] = array('yourmodel_name');

For Multiple Models :

$autoload['model'] = array('yourmodel_name1','yourmodel_name2','yourmodel_name3');

Example : Codeigniter autoload models

$autoload['model'] = array('My_first_model');

Now you can access this model without loading it again in controller.

Example

<?php
class MyUsers extends CI_Controller {
 
   public function users(){
    // No need load model here you can call directly
     $data['users'] = $this->My_first_model->getData();
     $this->load->view('MyUsers_view', $data);

  }

}
?>


User Ans/Comments

📖 Read More


Advertisements