我一直在查看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