Model
What is a Model?

Models is Class that inherit CI_Model. When are work with database like insert record,update record etc. so we create function in Model class and call from controller.We save Model classes in application/models/ folder. Model class name and model page name should be same like controller. you can not directly access model, you can run only from controller. You can see by default there is no any model.

Example 1:

Create this class file and save this application->models, And name of class name and page name should be same and start with capital letter.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User_Model extends CI_Model {

public function showuser()
{

echo "This is show user function";
}

}

How to access Model.

You can call and access model from controller only, so this is user controller where we load model, then we call model function showuser

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User extends CI_Controller {

public function index()
{
$this->load->model('user_model');
$this->user_model->showuser();
}

}

How to call -

You can just run your controller model is automatically call.


Previous
Next