codeigniter从控制器中的模型获取返回的数据变量,并在条件语句中使用它
我的搜索实现有什么问题,这里是我希望实现的 查看页面(表单)->控制器(表单数据变量)->模型(查询数据库并传递给控制器)如果有结果返回TRUE else return FALSE->控制器(从模型获取数据)如果为TRUE显示表中的数据如果为FALSE显示无结果返回消息 以下是我的页面:codeigniter从控制器中的模型获取返回的数据变量,并在条件语句中使用它,codeigniter,Codeigniter,我的搜索实现有什么问题,这里是我希望实现的 查看页面(表单)->控制器(表单数据变量)->模型(查询数据库并传递给控制器)如果有结果返回TRUE else return FALSE->控制器(从模型获取数据)如果为TRUE显示表中的数据如果为FALSE显示无结果返回消息 以下是我的页面: view: <form action="<?php echo site_url('retrieve')?>" method="post"> <input type="text
view:
<form action="<?php echo site_url('retrieve')?>" method="post">
<input type="text" name="id">
....
</form>
model:
public function retrieve($id)
{
$search = "SELECT * FROM table";
$result = $this->db->conn_id->prepare($search);
$result->execute();
if($result->rowCount()>0){
return $query_result = $result->fetchAll(PDO::FETCH_ASSOC);
}
}
controller:
public function retrieve_info()
{
$id = $this->input->post('id'),
$this->load->model('search_model');
$this->search_model->retrieve($id);
$data['query_result'] = $this->search_model->retrieve($id);
$this->load->view('display',$data);
}
视图:
首先,表单操作链接到控制器中的检索函数。但是,从您的示例来看,控制器中没有检索函数,只有在模型中
视图:
<form action="<?php echo site_url('retrieve')?>" method="post">
<input type="text" name="id">
....
</form>
控制器:
public function retrieve()
{
if($_POST){
$id = $this->input->post('id'),
$this->load->model('search_model');
$data['query_result'] = $this->search_model->retrieve($id);
$this->load->view('display',$data);
}else {
//form failed to submit via post
}
}
public function retrieve()
{
if($_POST){
$id = $this->input->post('id'),
$this->load->model('search_model');
$data['query_result'] = $this->search_model->retrieve($id);
$this->load->view('display',$data);
}else {
//form failed to submit via post
}
}