我收到错误消息:在我的视图中foreach()的无效参数。我想显示我的MySQL表中的所有条目,但我一直在收到错误消息。我是Codeigniter的新手,无法真正弄清楚如何解决这个问题。该代码如下......请帮助我为foreach()提供的参数无效codeigniter
user_model.php
<?php
foreach ($daftar as $data) :
?>
<tr>
<td><?php echo $data->id_petugas; ?></td>
<td></td>
<td></td>
<td></td>
<td>
<button class="btn edit"><i class="icon-edit"></i></button>
<button class="btn btn-danger remove" data-toggle="confirmation">
<i class="icon-remove"></i></button>
</td>
</tr>
<?php
endforeach;
?>
user_controller
<?php
class User_controller extends CI_Controller{
function __Construct()
{
parent ::__construct();
}
function user(){
$this->load->model('user_model');
$data['daftar'] = $this->user_model->get_user_all();
$this->load->view('daftar_user',$data);
}
daftar_user.php
<?php
foreach ($daftar as $data) :
?>
<tr>
<td><?php echo $data->id_petugas; ?></td>
<td></td>
<td></td>
<td></td>
<td>
<button class="btn edit"><i class="icon-edit"></i></button>
<button class="btn btn-danger remove" data-toggle="confirmation">
<i class="icon-remove"></i></button>
</td>
</tr>
<?php
endforeach;
?>
我已经从这个错误文件
get_user_all看起来像什么? (你没有发布你的模型,你发布了两次你的观点。) – 2015-01-20 22:10:56
对不起,先生,这种模式 – 2015-01-21 00:34:03
功能get_user_all() \t \t { \t \t \t $查询= $这个 - > DB->查询( “SELECT * FROM petugas为了通过ASC”); \t \t \t return $ query-> result(); \t \t \t \t \t $ this-> db-> select('*'); \t \t \t $ this-> db-> from('petugas'); \t \t \t $ this-> db-> order_by('id_petugas','ASC'); \t \t \t \t \t \t $ query = $ this-> db-> get(); \t \t \t \t如果($查询 - > NUM_ROWS()> 0){ \t \t \t \t \t的foreach($查询 - >结果()作为$数据){ \t \t \t \t \t \t $ daftar [] = $数据; \t \t \t \t \t} \t \t \t \t回$ daftar; \t \t \t \t} \t \t \t \t \t} – 2015-01-21 00:34:47