我一直在查看codeigniters網站上的活動記錄指南,我想知道哪裏把where子句放在模型或控制器中?我認爲它在模型中,但不知道如何實現它。 $ where =「EmpName ='Donny」; $這 - > DB->其中($其中);不知道在哪裏把where子句在codeigniter
控制器稱爲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>
我留下了評論,有人留下的answere,它已被刪除?那就更奇怪了 – Donny 2015-02-05 23:41:25
是的..只在模型文件中輸入你的where子句... – 2015-02-06 12:14:45