【问题标题】:Show New Page Table Detail From Page Table User Codeigniter显示来自页表用户 Codeigniter 的新页表详细信息
【发布时间】:2019-09-14 05:06:29
【问题描述】:

我在这个项目中使用 CodeIgniter。在名为“v_presensi_user_admin_awal”的项目的第一页中,我必须显示一个名为“user”的表。数字列有“no”,详细按钮有“Detail”,用户名有“nama_user”。当我单击详细信息按钮时,它应该转到“v_presensi_user”以显示我单击的用户的详细信息。但它显示了一些错误。

A PHP Error was encountered
Severity: Notice

Message: Trying to get property 'nama_user' of non-object

Filename: views/v_presensi_user.php

Line Number: 26

Backtrace:

File: /var/www/html/bolehstation/myreport/application/views/v_presensi_user.php
Line: 26
Function: _error_handler

File: /var/www/html/bolehstation/myreport/application/views/template.php
Line: 183
Function: view

File: /var/www/html/bolehstation/myreport/application/controllers/Presensi_user.php
Line: 33
Function: view

File: /var/www/html/bolehstation/myreport/index.php
Line: 315
Function: require_once

以及其他详细信息列的以下错误。 首先,控制器“Presensi_user”显示“v_presensi_user_admin_awal”:

public function index()
    {
        $data['konten']="v_presensi_user_admin_awal";
        $this->load->model('presensi_m');
        $data['data_presensi']=$this->presensi_m->get_pres_user_adm_awal();
        $this->load->model('status_m');
        $data['data_status']=$this->status_m->get_status();
        $this->load->model('user_m');
        $data['data_user']=$this->user_m->get_user();
        $this->load->model('pengajar_m');
        $data['data_pengajar']=$this->pengajar_m->get_pengajar();
        $this->load->view('template', $data, FALSE);
    }

在模型“presensi_m”中获取方法“get_pres_user_adm_awal”:

public function get_pres_user_adm_awal()
  {
      $data_presensi= $this->db
        ->join('user','user.id_user=presensi.id_user')
        ->join('status','status.id_status=presensi.id_status')
        ->join('pengajar','pengajar.id_pengajar=presensi.id_pengajar')
        ->get('presensi')->result();
      return $data_presensi;
  }

在“v_presensi_user_admin_awal”中:

<table class="table table-hover table-striped">
   <tr>
      <th>NO</th>
      <th>AKSI</th>
      <th>NAMA SISWA</th>
   </tr>
   <?php
     $no=0;
     foreach ($data_user as $usr) {
       $no++;
       echo '<tr>
         <td>'.$no.'</td>
         <td>'.anchor('Presensi_user/detail/'.$usr->id_user,'<div class="btn btn-info">Detail</div>').'</td>
         <td>'.$usr->nama_user.'</td>
       </tr>';
     }
   ?>
</table>

如果我单击详细信息按钮,它应该继续执行控制器“Presensi_user”中称为“详细信息”的方法:

public function detail($id_presensi)
    {
        $this->load->model('presensi_m');
        $detail = $this->presensi_m->detail_data($id_presensi);
        $data['detail'] = $detail;
        $data['konten']="v_presensi_user";
        $this->load->view('template', $data, FALSE);
    } 

模型“presensi_m”中称为方法“detail_data”的方法:

public function detail_data($id_presensi = NULL)
  {
    $query = $this->db->where('id_presensi', $id_presensi)->get('presensi')->row();
    return $query;
  }

最后它应该在视图“v_presensi_user”中出现详细信息:

<table class="table table-hover table-striped">
  <tr>
    <th>NO</th>
    <th>NAMA SISWA</th>
    <th>NAMA PENGAJAR</th>
    <th>HARI</th>
    <th>DATANG</th>
    <th>PULANG</th>
    <th>STATUS</th>
  </tr>
  <?php
    $no=0;
    $no++;
    echo '<tr>
       <td>'.$no.'</td>
       <td>'.$detail->nama_user.'</td>
       <td>'.$detail->nama_pengajar.'</td>
       <td>'.$detail->hari.'</td>
       <td>'.$detail->datang.'</td>
       <td>'.$detail->pulang.'</td>
       <td>'.$detail->status.'</td>
    </tr>'
  ?>
</table>

请帮我解决这个问题。我尝试并搜索了很多方法,但找不到正确的方法。

【问题讨论】:

  • var_dump($query) in detail_data 因为看起来查询没有返回任何行。用错误的 id 或拼写错误猜测一些问题。

标签: php html css database codeigniter-3


【解决方案1】:
  public function detail_data($id_presensi = NULL)
  {
    $this->db->select('*');
    $this->db->from('presensi');
    $this->db->where('id_presensi',$id_presensi);
    $query = $this->db->get();
    return $query->result();
  }

    public function detail($id_presensi)
   {
      $this->load->model('presensi_m');
      $data['detail'] = $this->presensi_m->detail_data($id_presensi);
      $data['konten']="v_presensi_user";
      $this->load->view('template', $data);
   } 

【讨论】:

  • 非常感谢...解决了!!尽管您的代码缺少连接部分,但它仍然让我知道该怎么做。谢谢你..
猜你喜欢
  • 2015-05-20
  • 1970-01-01
  • 2014-09-26
  • 1970-01-01
  • 2020-01-20
  • 1970-01-01
  • 2016-05-01
  • 2018-06-08
  • 2019-09-23
相关资源
最近更新 更多