I have been looking over the active records guide from codeigniters site and I am trying to figure where to put the where clause in the model or controller. I think it goes in the model but not sure how to implement it. $where = "EmpName='Donny"; $this->db->where($where);
Controller called Home.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller
{
public function index()
{
$this->load->model('HomeModel');
$data['records'] = $this->HomeModel->getData();
$this->load->view('HomeView',$data);
}
}
HomeModel.php
<?php
class HomeModel extends CI_Model{
public function getData(){
$query = $this->db->get('requests');
return $query->result();
}
}
HomeView.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home View</title>
</head>
<body>
<h1>Our DB Results:</h1>
<?php
foreach($records as $r){
echo $r->EmpName." ".$r->Department."<br>";
};?>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire