codeigniter 代码触发器4:将$data传递到视图文件

0wi1tuuw  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(124)

有人能帮我吗?我不知道如何在视图文件上显示结果。我尝试使用$this->load->view('list-logs',$data);,但它显示错误Call to a member function view() on null
控制器

public function getLogs()
    {
        helper(['form']);

        $EstMod = new EstMod();
        $data['est_data'] = $EstMod->orderBy('e_id', 'DESC')->findAll();

        $rep_est = $this->request->getPost('rep_est');
        $rep_date = $this->request->getPost('rep_date');

        $builder = $this->db->table("logs as l");
            $builder->select('l.l_id, u.fname, u.mname, u.lname, u.dept, u.user_type, u.u_grdsec, e.e_name, l.date_added, DATE(l.date_added), date_format(l.date_added, "%H:%i") as "time"');
            $builder->join('users as u', 'l.u_id = u.u_id');
            $builder->join('establishment as e', 'l.e_id = e.e_id');
            $builder->where('DATE(l.date_added)', $rep_date);
            $builder->groupBy('date_format(l.date_added, "%H:%i"), l.u_id');
            $data['logs_data'] = $builder->get()->getResult();

        $this->load->view('list-logs',$data);
        //echo "<pre>";
        //print_r($data);

    }

检视

<?php

if ($logs_data) {
    foreach ($logs_data as $row) {
        
        echo '
        <tr>
          <td>' . $row['date_added'] . '</td>
          <td>' . $row['lname'] . ", " . $row['fname'] . ", " . $row['mname'] . '</td>';
        
        if ($row['user_type'] == 'S') {
            echo '<td>STUDENT</td>';
        } else if ($row['user_type'] == 'E') {
            echo '<td>EMPLOYEE</td>';
        } else if ($row['user_type'] == 'P') {
            echo '<td>VISITOR</td>';
        }
        
        if ($row['dept'] == 'GS') {
            echo '<td>GRADE SCHOOL</td>';
        } else if ($row['dept'] == 'JHS') {
            echo '<td>JUNIOR HIGH SCHOOL</td>';
        } else if ($row['dept'] == 'SHS') {
            echo '<td>SENIOR HIGH SCHOOL</td>';
        }
        
        echo '</td>
        <td>' . $row['u_grdsec'] . '</td>';
    }
}

?>
ars1skjm

ars1skjm1#

如果你使用CodeIgniter 4,那么你必须像这样调用视图ont控制器:

echo view('my_view', $data)

相关问题