douzhenao6515 2016-07-19 01:50
浏览 36

无法将数据从模型传递到视图

Hello i'm having problem on passing some data from my Model to my View, with this following code:

Controller:

class Welcome extends CI_Controller {


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

        $this->load->library('session');
        $this->load->helper('form');
        $this->load->helper('url');

     }
    public function testing(){

      $query = $this->Model->getEmployees();
      if(isset($query)){
       $data['fds'] =  $query;
      }

      $this->load->view('UserPage', $data);
     }
}

Model:

class Model extends CI_Model{

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

        $this->load->library('session');
     }

 public function getEmployees(){
        $this->db->select('*');
         $this->db->where("idcliente='".$_SESSION['userid']."'");
         $query=$this->db->get('marcacao');
        return $query->num_rows() > 0 ? $query->result() : NULL;
 }
}

View:

<table class="table table-striped table-bordered">
     <tr> 
      <td><strong>Employee Id</strong></td>
      <td><strong>First Name</strong></td>
      <td><strong>Last Name</strong></td>
    </tr> 
     <?php foreach($fds as $employee){?>
     <tr>
      <td><? =$employee->data;?></td>
      <td><? =$employee->hora;?></td>
      <td><? =$employee->tipo;?></td>
     </tr>     
        <?php }?>  
    </table>

I've tried several things that I've seen here but none works... Hope you can help me.

  • 写回答

4条回答 默认 最新

  • donglu1881 2016-07-19 02:57
    关注

    first things change this :

      $query = $this->Model->getEmployees();
      if(isset($query)){
       $data['fds'] =  $query;
      }
    

    become :

    $id = $_SESSION['userid'];
    $data["fds"] = $this->Model->getEmployees($id);
    

    now on your model :

    public function getEmployees($id){
         $this->db->select('*');
         $this->db->where("idcliente=",$id);
         $query=$this->db->get('marcacao');
         return $query->result_array();
    

    now in your view()

    <?php
     if($fds != NULL){
     foreach($fds as $employee){?>
       <tr>
         <td><?=$employee["data"];?></td>
         <td><?=$employee["hora"];?></td>
         <td><?=$employee["tipo"];?></td>
       </tr>     
     <?php 
     }
      }?>  
    
    评论

报告相同问题?

悬赏问题

  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接