Articles → PHP CODEIGNITER → Model In Codeigniter
Model In Codeigniter
Purpose
How To Create A Model?
<?php
class mymodel extends CI_Model{
public function DoEcho()
{
echo "My first model";
}
}
How To Call A Model In Controller Class?
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class About extends CI_Controller{
public function Index(){
$this->load->model('mymodel');
$this->mymodel->DoEcho();
$this->load->view('About');
}
}
Click to Enlarge
Model Alias
$this->load->model('mymodel');
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class About extends CI_Controller{
public function Index(){
$this->load->model('mymodel', 'mm');
$this->mm->DoEcho();
$this->load->view('About');
}
}