dourui7186 2013-08-13 20: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-13 21: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部