CodeIgniter-错误消息:未定义的变量

据我所知,我有这段代码在定义数据的地方,这些是我得到的错误:

  

遇到PHP错误

     

严重性:通知

     

消息:未定义的变量:empdata

     

文件名:views / employee.php

     

行号:51 **

     

回溯:

     

文件:C:\ xampp \ htdocs \ providentfund \ application \ views \ employee.php   线:51   功能:_error_handler

     

文件:   C:\ xampp \ htdocs \ providentfund \ application \ libraries \ BaseController.php   行:99功能:查看

     

文件:   C:\ xampp \ htdocs \ providentfund \ application \ controllers \ Employee.php   行:19功能:loadViews

     

文件:C:\ xampp \ htdocs \ providentfund \ index.php行:315功能:   require_once

控制器:

      public function display_all()
      {
          $result=$this->Employee_model->display_all();
          $data['empdata']=$result;
         $this->loadViews("employee",$this->global,NULL);

      }

型号:

      function display_all()
      {
      $query=$this->db->query("select * from employetbl");

      return $query->result();
      }

和视图:

    <table id="example1" class="table table-bordered table-striped">
              <thead>
              <tr>
                <th>Rendering engine</th>
                <th>Browser</th>
                <th>Platform(s)</th>
                <th>Engine version</th>
                <th>CSS grade</th>
              </tr>
              </thead>
              <tbody>
              <?php
              $cnt=1;

              foreach($empdata as $rec)
              {
                print_r($empdata);
                die();
              ?>
              <tr>
                <td><?php echo $rec['fullName'];?></td>

              </tr>
              <?php
              // for serial number increment
              $cnt++;
              } ?>

为什么会出现错误消息“未定义的变量”

jiangxue2913 回答:CodeIgniter-错误消息:未定义的变量

我认为问题出在您的控制器上

File "D:\local\Temp\jobs\continuous\get-stock-details\03j5dtql.crz\lxml\html\__init__.py",line 53,in <module>
from .. import etree
ImportError: cannot import name 'etree'

您正在使用$ this-> global调用loadViews,但未在其中定义“ empdata”。

您应该尝试更改此设置:

public function display_all()
      {
          $result=$this->Employee_model->display_all();
          $data['empdata']=$result;
         $this->loadViews("employee",$this->global,NULL);

      }

对此:

$this->loadViews("employee",NULL);
,

控制器

public function display_all(){
     $result=$this->Employee_model->display_all();
     $data['empdata']=$result;
     $this->load->view('employee',$data);
}
,

在控制器中

public function display_all()
      {
          $result=$this->Employee_model->display_all();
          $data['empdata']=$result;
         $this->loadViews("employee",$data);

      }

在模型中

function display_all()
      {
      $query=$this->db->query("select * from employetbl");

      $result = array();
        foreach ($query->result_array() as $value) {
            $res['variable_name'] = $value['column_name'];
            array_push($result,$res);
        }
        return $result;
      }
本文链接:https://www.f2er.com/3139047.html

大家都在问