Display Simple One Data
17
May
2013

For model: Open “employee_model.php” within CodeIgniter\system\application\models. Add following function:

<?php
class Employee_model extends Model{
function Employee_model(){
parent::Model();
}
function employee_getall(){
$this->load->database();
$query = $this->db->get->employee();
return $query->result();
}

function employee_get(){
$this->load->database();
$query = $this->db->getwhere('employee',array('id'=>1));
}
}
?>

For Controller: Open “employee.php” within CodeIgniter\system\application\controllers. Add following function:

 

<?php
class employee extends Controller{
function employee(){
parent::Controller();
}

function GetAll(){
$this->load->model('employee_model');
$data['query'] = $this->employee_model->employee_getall();
$this->load->view('employee_viewall',$data);
}

function Get(){
$this->load->model('employee_model');
$dta['query'] = $this->employee_model->employee_get();
$this->load->view('employee_view',$data);
}
}
?>

 

For View: Open “employee_view.php” within CodeIgniter\system\application\views. Enter following code:

 Hi, <?=$query['name']?>. Your Id is <?=$query['id']?>

Point your browser to http://localhost/CodeIgniter/index.php/employee/get.

  • 1007 View
  • Pin It