RE: how you will load or add a model in CodeIgniter?

how you will load or add a model in CodeIgniter?

rajesh Trainee Asked on June 7, 2018 in CODEIGNITER.
Add Comment
1 Answers

What is a Model?

Models are PHP classes that are intended to work with data in your database. For instance, suppose you utilize CodeIgniter to deal with a blog. You may have a model class that contains capacities to embed, refresh, and recover your blog information. Here is a case of what such a model class may resemble:


Add Model

Create a Users_model.php file in application/models  directory.

Inside the class create methods for data processing.

Create a getUsers() method to select all records from the user_master table and return an Array response.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main_model extends CI_Model {
function getUsers(){
$result= array();
// Select record
$q = $this->db->get('user_master'); $result= $q->result_array(); return $result; } }


Loading a Model

Your models will typically be loaded and called from within your controller methods. To load a model you will use the following method:

Team Leader Answered on November 18, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.