I am using codeigniter framework and on one of the controllers I have tis code below
public function index() {
$this->data['users'] = $this->user_m->get();
$this->data['subview'] = 'admin/usuarios/index';
$this->load->view('admin/layout_principal', $this->data);
}
My problem is when I try to use the data users and subviews into a view. As you can see "subviews" has a location of another view file, and when I call "subviews" in the main view like this:
<div class="span9">
<?php $this->load->view($subview); ?>
</div>
I get this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: subview
Filename: admin/layout_principal.php
Line Number: 19
An Error Was Encountered
Unable to load the requested file: .php*
And I said "well, its just a location I'll put it directly, and go on loading my users data, but then when I use "users" from the data like this:
<?php if(count($users)): foreach($users as $user):?>
<tr>
<td><?php echo anchor('admin/usuario/editar/' . $user->id, $user->email);?></td>
<td><?php echo btn_edit('admin/usuario/editar', $user->id); ?></td>
<td><?php echo btn_delete('admin/usuario/borrar', $user->id); ?></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="3">No users found</td>
</tr>
<?php endif;?>
I get this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: users
Filename: usuario/index.php
Line Number: 15
The view it's not recognizing the data variables, I had searched and tried for ways to solve this but I still with the same problem, and well, I posted this for help as last resource, can you help me? what can I do to make the view recognize the data, because I can't find what's wrong with this.
userstry to check if isset or not$this->load->model('user_m');in index I don't see it.