Reputation: 237
I'm logging into my system and once I login, the idea is that the menu is updated according to the type of user profile, for which I'm doing from the database and showing the menu through a Foreach. However within the Foreach, when comparing one of the rows with a number, that is, with an id I get this error message and other similar ones:
Message: Undefined property: mysqli::$id_man
So I think that I'm not recognizing the value of the row, why is it happening, how could I correct it?
Controller
public function ingresar(){
$nombre_usu= $this->input->post('nombre_usu');
$pass_usu= $this->input->post('pass_usu');
$res= $this->M_Login->ingresar($nombre_usu,$pass_usu);
if ($res ==1) {
$this->load->view('layouts/Header.php');
// if the user exists, show the menu according to his profile
$data['menu_barra'] = $this->M_Login->show_menu();
$this->load->view('layouts/Menu.php', $data);
$this->load->view('usuarios/V_Index.php');
$this->load->view('layouts/Footer.php');
} else {
$data['mensaje'] = "Usuario o contraseña Incorrecta";
$this->load->view('V_Login',$data);
}
}
Model
public function show_menu(){
$id_tip= $this->session->userdata('tipo');
$this->db->select('id_mc, id_tip, id_man');
$this->db->from('mantenedores_cuenta');
$this->db->where('id_tip',$id_tip);
$menu = $this->db->get();
$horarios ="";
$informes="";
foreach ($menu as $row) {
if ($row->id_man == 1 ) {
$horarios .='<li class="active"><a href="<?= base_url("index.php/C_Horarios"); ?>"><i class="fa fa-circle-o"></i>Administrar Horarios</a></li>';
}
if ($row->id_man == 2 ) {
$horarios .='<li><a href="<?= base_url("index.php/C_Calendar"); ?>"><i class="fa fa-circle-o"></i>Agendar Citas</a></li>';
}
if ($row->id_man == 3 ) {
$horarios .='<li><a href="<?= base_url("index.php/C_Citas"); ?>"><i class="fa fa-circle-o"></i>Consultar Citas</a></li>';
}
if ($row->id_man == 4 ) {
$informes .='<li class="active"><a href="<?= base_url("index.php/C_Porcentaje"); ?>"><i class="fa fa-circle-o"></i>Porcentaje de Citas</a></li>';
}
} //Fin del Foreach
$menu_barra="
<ul class='sidebar-menu'>
<li class='header'>MENU</li>
<li class='active treeview'>
<a href='#'>
<i class='fa fa-fw fa-calendar'></i> <span>Horarios</span>
<span class='pull-right-container'>
<i class='fa fa-angle-left pull-right'></i>
</span>
</a>
<ul class='treeview-menu'>
'$horarios'
</ul>
</li>
<li class='treeview'>
<a href='#'>
<span class='glyphicon glyphicon-stats'></span><span>Informes</span> <i class='fa fa-angle-left pull-right'></i>
</a>
<ul class='treeview-menu'>
'$informes'
</ul>
</li>
<li><a href='documentation/index.html'><i class='fa fa-book'></i> <span>Documentación</span></a></li>
<li><a href='documentation/index.html'><i class='fa fa-fw fa-sign-out'></i><span>Salir</span></a></li>
</ul> ";
return ($menu_barra);
}
View (menu)
<aside class="main-sidebar">
<section class="sidebar">
<div class="user-panel">
<div class="pull-left image">
<img src="<?php echo base_url();?>assets/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
</div>
<div class="pull-left info">
<p><?php echo $this->session->userdata('s_usuario');?></p>
<a href="#"><i class="fa fa-circle text-success"></i><?php echo $this->session->userdata('cuenta');?></a>
</div>
</div>
// show the menu according to your profile
<?php echo $menu_barra; ?>
</section>
<!-- /.sidebar -->
I also tried to show it in this way, but I was not allowed in an array or at least that was what the message said, example: $row["id_man"] == 3
Upvotes: 0
Views: 488
Reputation: 4821
Change
foreach ($menu as $row) {
to
foreach ($menu->result() as $row) {
See here for documentation
You could also use
foreach ($menu->result_array() as $row) {
and access properties like
$row['id_man'];
Upvotes: 4
Reputation: 1124
Ensure that your table mantenedores_cuenta
has the following column: id_man
Upvotes: 0