为什么不能使用 stdClass 类型的对象作为数组


why Cannot use object of type stdClass as array in

>我正在尝试进行分页,这正在工作,但不知道为什么我的编辑和 delte 功能停止工作。这是我的控制器

function view($page=0){
                $config = array();
                $config["base_url"] = base_url() . "index.php/employee/view";
                $config["total_rows"] = $this->employee_model->getTotalEmployeeCount();
                $config["per_page"] =5;
                $this->pagination->initialize($config);
                $this->data["results"] = $this->employee_model->getEmployee($config["per_page"], $page);
                $this->data["links"] = $this->pagination->create_links();
                $this->data['title'] = 'Payroll System';
                $this->data['message'] = $this->session->flashdata('message');
                $this->load->view('employee_view', $this->data);
    }

这是我的模型

function getTotalEmployeeCount() {
            return $this->db->count_all('user');
        }
      function getEmployee($limit, $start) {
            $this->db->limit($limit, $start);
            $this->db->select('id,firstname,lastname,presentadress,contactno,dateofjoining,email');
            $qry= $this->db->get('user');
        return $qry->result_array();
         }

这是我的观点

 <?php
    foreach ($results as $m){
    ?>
      <tr style="text-align:center;">
                  <td><?php echo $m['id'] ?></td>
                  <td><?php echo $m['firstname'] ?></td>
                  <td><?php echo $m['lastname'] ?></td>
                  <td><?php echo $m['dateofjoining'] ?></td>
                  <td><?php echo $m['presentadress'] ?></td>
                  <td><?php echo $m['contactno'] ?></td>
                  <td><?php echo $m['email'] ?></td>
   <td><a href="<?php echo site_url('employee/edit_employee/'.$m->id) ?>" class="btn btn-primary btn-mini">Edit</a></td>
          <td>
          <?php 
          echo anchor('employee/delete_employee/'.$m->id, 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
          ?>
          </td>
    <?php
    }
    ?>
    <?php echo $this->pagination->create_links()?>

在我的模型中,如果更改为结果result_array则给出错误"无法使用 stdClass 类型的对象作为数组"。这就是为什么我用result_array,但现在删除和编辑功能不起作用我收到"尝试获取非对象的属性">的错误。帮助我结束此错误

如果你在模型中更改result result_array,你应该像这样访问这些元素。

<td><?php echo $m->id; ?></td>
<td><?php echo $m->firstname; ?></td>
<td><?php echo $m->lastname; ?></td>

试试这样

<td><?php echo $m->id; ?></td>
<td><?php echo $m->firstname; ?></td>
<td><?php echo $m->lastname; ?></td>

更改视图中的单行:

<?php
    foreach ($results as $m){
    ?>
      <tr style="text-align:center;">
                  <td><?php echo $m['id'] ?></td>
                  <td><?php echo $m['firstname'] ?></td>
                  <td><?php echo $m['lastname'] ?></td>
                  <td><?php echo $m['dateofjoining'] ?></td>
                  <td><?php echo $m['presentadress'] ?></td>
                  <td><?php echo $m['contactno'] ?></td>
                  <td><?php echo $m['email'] ?></td>
   <td><a href="<?php echo site_url('employee/edit_employee/'.$m->id) ?>" class="btn btn-primary btn-mini">Edit</a></td>
          <td>
          <?php 
          //change  here ///
          echo anchor('employee/delete_employee/'.$m['id'], 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
          ?>
          </td>
    <?php
    }
    ?>
    <?php echo $this->pagination->create_links()?>