【问题标题】:How can i see profile details according to id?如何根据 id 查看个人资料详情?
【发布时间】:2014-01-31 14:14:57
【问题描述】:

我正在尝试查看个人资料详细信息,但在获取“id”时出现问题。但我有一些错误:严重性:警告

消息:customers::details() 缺少参数 1 文件名: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> <?}?>  

    ...

【问题讨论】:

  • 你有一个公共函数 details($id){ 这在哪里调用?
  • 基本上你没有将 ID 传递给 details 方法。尝试在调用 details 方法之前 var_dump $id 并查看它是否正确

标签: php codeigniter profile detailsview


【解决方案1】:

试试这个

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

你错误地添加了 return $query->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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-30
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多