Posted On: Feb 22, 2018
In Codeigniter, models will typically be loaded and called from within your controller methods. To load a model you will use the following method:
$this->load->model('model_name');
If your model is located in a sub-directory, include the relative path from your model’s directory. For example, if you have a model located at application/models/blog/Posts.php you’ll load it using:
$this->load->model('blog/Posts');
Once your Model loaded, you will access its methods using an object with the same name as your controller:
Example
class Blog_controller extends CI_Controller { public function blog() { $this->load->model('blog'); $data['query'] = $this->blog->get_last_ten_entries(); $this->load->view('blog', $data); } }
Never Miss an Articles from us.
What is the current version of Codeigniter?..
How to check the version of CodeIgniter framework?..