观点:
<table class="table table-hover">
<tr>
<th>Heading</th>
<th>Description</th>
</tr>
<?php foreach ($result as $row) { ?>
<tr>
<td><?php echo $row->heading_name ;?></td>
<td><?php echo $row->description_name; ?></td>
</tr>
<?php } ?>
</table>
型号:
function view_description(){
$this->db->order_by("id","DESC");
$query = $this->db->get("description_update");
return $query->result();
}
控制器:
public function update_heading(){
$config = array(
array(
'field' =>'heading_name',
'label' =>'Name',
'rules' => 'trim|required'
),
array(
'field' => 'description_name',
'label' => 'Description',
'rules' => 'trim|required'
)
);
$this->form_validation->set_rules($config);
if ($this->form_validation->run()== FALSE)
{
$this->load->view('modules/admin/general.php');
}
else{
$data = array(
'heading_name' => $this->input->post('heading_name'),
'description_name' => $this->input->post('description_name')
);
$this->description_model->add_description($data);
$data['message'] = 'Data inserted Successfully';
$this->load->view('modules/admin/general.php',$data);
}
$data['result']= $this->description_model->view_description();
$this->load->view('modules/admin/general.php',$data);
// print_r($data);
}
我想在我的视图文件中查看结果数据,但是当$ result数据显示另一个视图文件中的结果时,它表示找不到结果变量但是在相同的代码中。 我不知道该怎么办。 注意:我是CodeIgniter的新手
TIA
答案 0 :(得分:0)
无需在29行中加载此视图,因为您的目标是加载结果数据。
$这 - &GT;负载&gt;查看( '模块/管理/ general.php',$数据);
答案 1 :(得分:0)
尝试将$data['result']
置于代码顶部,并在表单的错误部分添加$data
以及
加载视图时,您也不需要.php
$this->load->view('modules/admin/general', $data);
功能
public function update_heading(){
$config = array(
array(
'field' =>'heading_name',
'label' =>'Name',
'rules' => 'trim|required'
),
array(
'field' => 'description_name',
'label' => 'Description',
'rules' => 'trim|required'
)
);
$this->form_validation->set_rules($config);
$data['message'] = '';
// $data['result'] = array();
$data['result'] = $this->description_model->view_description();
if ($this->form_validation->run()== FALSE) {
$this->load->view('modules/admin/general', $data);
} else {
$data = array(
'heading_name' => $this->input->post('heading_name'),
'description_name' => $this->input->post('description_name')
);
$this->description_model->add_description($data);
$data['message'] = 'Data inserted Successfully';
$this->load->view('modules/admin/general',$data);
}
}