我正在登录我的系统,一旦我登录,我的想法是根据用户配置文件的类型更新菜单,我正在从数据库中进行更新,并通过Foreach显示菜单。但是在Foreach中,当将其中一行与一个数字进行比较时,也就是说,使用id我得到此错误消息和其他类似的消息:
Message: Undefined property: mysqli::$id_man
所以我认为我没有认识到该行的价值,为什么会发生这种情况,我该怎么纠正呢?
控制器
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);
}
}
模型
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);
}
查看(菜单)
<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 -->
我也尝试以这种方式显示它,但我不允许在数组中或至少这是消息所说的,例如:$ row [“id_man”] == 3
答案 0 :(得分:4)
更改
foreach ($menu as $row) {
到
foreach ($menu->result() as $row) {
请参阅here了解文档
您也可以使用
foreach ($menu->result_array() as $row) {
并访问
等属性$row['id_man'];
答案 1 :(得分:0)
确保您的表格mantenedores_cuenta
包含以下列:id_man