Code Igniter未定义的变量用户

时间:2016-06-16 09:17:40

标签: codeigniter

我需要这个未定义变量用户的帮助:

enter image description here

我已在用户控制器中设置变量用户,如下所示:

class User extends Admin_Controller
{

public function __construct()
{
    parent :: __construct();

}

public function index()
{

    $this->data['users']=$this->user_m->get();
    $this->data['subview']='admin/user/index';
    $this->load->view('admin/_layout_main', $this->data);
}

这是我的视图文件index.php中的代码

<tbody>
<?php if(count($users)): foreach($users as $user): ?>      
<?php endforeach; ?>
<tr>

<td><?php echo anchor('admin/user/edit/' . $user->id, $user->email); ?></td>          
<td><?php echo btn_edit('admin/user/edit/' . $user->id); ?></td>    
<td><?php echo btn_delete('admin/user/delete/' . $user->id);?></td>

</tr>    <?php else: ?>
<tr>
<td colspan="3">We could not find any users.</td>
</tr>

<?php endif; ?>

</tbody>

1 个答案:

答案 0 :(得分:0)

我通过以下方式解决了这个问题:

  1. 删除用户$this->data['users']=$this->user_m->get();中的model(user_m)并在视图中创建变量,如下所示:

    <?php 
    $users=$this->user_m->get();
    if(count($users)):foreach($users as $user):
    ?>