1

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

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 更改为 result,则会出现“无法使用 stdClass 类型的对象作为数组”的错误。这就是我使用 result_array 的原因,但现在删除和编辑功能不起作用。我收到“尝试获取非对象的属性”帮我结束这个错误

4

3 回答 3

3

如果您resultresult_array模型中更改,则在视图中您应该像这样访问这些元素。

<td><?php echo $m->id; ?></td>
<td><?php echo $m->firstname; ?></td>
<td><?php echo $m->lastname; ?></td>
于 2013-08-19T12:08:16.930 回答
1

在您的视图中更改单行:

<?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()?>
于 2013-08-19T12:18:11.693 回答
1

试试这样

<td><?php echo $m->id; ?></td>
<td><?php echo $m->firstname; ?></td>
<td><?php echo $m->lastname; ?></td>
于 2015-12-30T08:33:51.863 回答