dourui7186 2013-08-14 04:52
浏览 37
已采纳

类stdClass的对象无法转换为字符串,并且分页无法正常工作

Finally my pagination worked.Still there are some problems.In every page its showing only one data and edit delete functionality not working.I tried changing almost everything.Any guidance will be great. *This is my controller*

function view($page=0){
        $config = array();
                $config["base_url"] = base_url() . "index.php/view_expenses/view";
                $config["total_rows"] = $this->emp_expenses_model->getTotalStudentCount();
                $config["per_page"] = 5;
                $this->pagination->initialize($config);
                $this->data["results"] = $this->emp_expenses_model->getStudent($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('view_expenses', $this->data);

    }

This is the code in my model

function getTotalStudentCount() {
            return $this->db->count_all("emp_expenses");
        }
      function getStudent($limit, $start) {
            $this->db->limit($limit, $start);
            $qry= $this->db->get("emp_expenses");
        return $qry->result();
         }

and this is the view

    <table cellspacing="0" cellpadding="2" border="0" id="tbl"  style="width:100%">
    <tr style="background-color:#045c97">
          <td class="heading">Expenses ID</td>
          <td class="heading">Employee ID</td>
          <td class="heading">Drop Down</td>
          <td class="heading">Mode OF Payment</td>
          <td class="heading">Amount</td>
          <td class="heading">Edit</td>
          <td class="heading">Delete</td>
    </tr>
     <?php
    foreach($results as $m)
      //var_dump($results);die('asd');
      ?> 
      <tr style="text-align:center;">
         <tr>
          <td><?php  echo $m->expenses_id ?></td>
          <td><?php  echo $m->id ?></td>
          <td><?php  echo $m->dropdown ?></td>
          <td><?php  echo $m->modeofpayment ?></td>
          <td><?php  echo $m->amount ?></td>
          <td><a href="<?php echo site_url('view_expenses/edit_expenses/'.$m) ?>"class="btn btn-primary btn-mini">Edit</a></td>
          <td>
          <?php 
          echo anchor('view_expenses/delete_expenses/'.$m, 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
          ?>
          </td>
      </tr>
       <?php echo $this->pagination->create_links()?>
</table>
  • 写回答

1条回答 默认 最新

  • douhan4812 2013-08-14 05:04
    关注

    Firstly, probably not related to the main problem but your class="" attribute on the edit button has no space between the start of the attribute and the closing quotes of the href.

    The main problem seems to be that your trying to echo $m, on this line:

    <?php echo site_url('view_expenses/edit_expenses/'.$m) ?>
    

    $m is an object (containing multiple variables of information), your getting an error because your trying to treat it like a string.

    Instead, you need to access one of these variables from within the object, just like you do further up in the code. I am guessing, you want the id, which would be $m->id.

    Give this a go instead:

    <?php echo site_url('view_expenses/edit_expenses/'.$m->id) ?>
    

    The same goes for your delete button.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料