我如何根据id查看个人资料详细信息?

时间:2014-01-31 14:14:58

标签: php codeigniter profile detailsview

我正在尝试查看个人资料详情,但是有关于获取'id'的问题。但我有一些错误:严重性:警告

消息:客户缺少参数1 :: details() 文件名:controllers / customers.php  和,

遇到PHP错误

严重性:注意

消息:未定义的变量:id

文件名:controllers / customers.php

这是我的模特:

function selectCustomer(){

    $this->db->select('*');
    $this->db->from('customers');

    $query = $this->db->get();

    return $query->result();
}
 function detailsCustomer($id){
    //$id= $_GET['ID'];
    //$this->db->select('*');
    //$this->db->from('customers');
    $this->db->where('ID', $id);
    $query = $this->db->get('customers');

}

这是我的控制器:

    publicfunction viewCustomers(){
     $this->load->model('CustomerModel');
     $result = $this->CustomerModel->selectCustomer();
     return $result;}

     public function details($id){

     $this->load->model('CustomerModel');

     $data["result"] = $this->CustomerModel->detailsCustomer($id);

        if($this->session->userdata('logged_in')){
         error_reporting(0);
         $session_data = $this->session->userdata('logged_in');
         $data1['email'] = $session_data['email'];
         $this->load->view('navbarview', $data1);
         $this->load->view('Detailsview',$data);
     }else{
         redirect('home', 'refresh');
     }
 }

这是我的观看页面:

...
    <table class="table table-hover">
      <thead>
        <tr>
          <th>Name</th>
          <th>Surname</th>
          <th>Email</th>
        </tr>
      </thead>
                  <?php  foreach ($user_data as $row) {
                echo "    
        <table class='table table-hover'>
      <tbody>
        <tr>
          <td>".$row->name."</td>
          <td>".$row->surname."</td>
          <td>".$row->email."</td>";?>


          <td><a href='http://localhost/CRM/customers/details/<?php echo $id;?>' type='button' class='btn btn-info'>Details</a></td>
      <td><a href='Editview.php' data-toggle='modal' class='btn btn-success'>Edit</a></td> 
    </tr>
  </tbody>
</table> <?}?>  

    ...

1 个答案:

答案 0 :(得分:1)

试试这个

function detailsCustomer($id){
   $this->db->where('ID', $id);
   $query = $this->db->get('customers');
   return $query->result();
}

您错误地添加了返回$ query-&gt; result();

也在视野中

更改

        <td><a href='http://localhost/CRM/customers/details/<?php echo $id;?>' type='button' class='btn btn-info'>Details</a></td>

进入

       <td><a href='http://localhost/CRM/customers/details/<?php echo $row->id;?>' type='button' class='btn btn-info'>Details</a></td>
相关问题