douti9286 2017-10-29 13:51
浏览 68
已采纳

Foreach中未定义的属性

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

  • 写回答

2条回答 默认 最新

  • drgdn82648 2017-10-29 13:57
    关注

    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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题