重定向页码代码点火器时出错

时间:2018-05-19 17:01:44

标签: php codeigniter web

我正在使用CodeIgniter框架开发一个Web。我是这种工作的新手。提交数据表单后重定向页面时遇到问题。我想在点击提交按钮后再次重定向到该表单页面(名为 detaillaporan )。但我得到的只是

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: laporan
Filename: home/detaillaporan.php

以下是控制器中的一些代码:

public function detailLaporan($kode_laporan)
{
    $data['page']='detaillaporan';
    $data['laporan'] = $this->Home_model->getLapDetail($kode_laporan);
    $data['id'] = $this->session->userdata('id');
    $data['respon'] = $this->Home_model->getResponInfo($kode_laporan)->result_array();
    $data['rsp'] = $this->Home_model->getResponInfo($kode_laporan)->num_rows();
    $data['kode_laporan'] = $this->session->set_userdata('kode_laporan');
    $this->load->view('home/master', $data);
}

public function beriRespon($kode_laporan){
        $data['kode_laporan'] = $kode_laporan;
        $data['id'] = $this->session->userdata('id');
        $this->load->library('form_validation');

    $this->form_validation->set_error_delimiters('<p style="color:red;">', '</p>');

    $this->form_validation->set_rules('isi_respon', 'Tulis Respon..', 'trim|required');

    if ($this->form_validation->run() == FALSE) {
        $data['page'] = 'detaillaporan';
        $data['kode_laporan'] = $kode_laporan;
        $this->load->view('home/master', $data);
    } else {
        $config['upload_path']    = './assets/img/laporan/';
        $config['allowed_types']  = 'gif|jpg|png';
        $config['remove_spaces']  = FALSE;

        //load upload library
        $this->load->library('upload' , $config);

        $imgData = array('upload_data' => $this->upload->data());
        $this->Home_model->inputRespon($imgData, $data);

        $data['message'] = 'Laporan berhasil dikirim!';
        $data['redir'] = 'laporan/'.$kode_laporan;
        $data['page'] = 'detaillaporan';
        $this->load->view('home/master', $data);
    }

}

以下是“routes.php”

中的代码
$route['laporan/(:any)']= 'home/detaillaporan/$1';
$route['beri-respon/(:any)'] = 'home/beriRespon/$1';

我期待着你的帮助。三江源!

1 个答案:

答案 0 :(得分:0)

在方法beriRespon中(可能是您的表单提交的位置),未定义变量laporan

从第一种方法(detailLaporan)中获取提示并添加:

$data['laporan'] = $this->Home_model->getLapDetail($kode_laporan);`
在if / else条件之前

如果并非总是需要此变量,请将其包围在视图中的isset中:

if (isset($laporan)) {
    print_r($laporan); // or whatever
}

这样你就不会得到未定义的错误。