函数Main(CodeIgniter)的参数太少

时间:2018-06-25 04:02:36

标签: php codeigniter

public function view_new_declaration_1($id,$token=''){
    $this->isLoggedIn();
    $dec_info = $this->Model_admin->get_new_declaration_by_id($id)->row();
    $data_admin = array(
    'token' => $token,
    'admin_info' => $this->model->getAdminInfo($this->session->userdata('email'))->row(),
    'dec_info' => $dec_info,
    'ia' => $this->Model_admin->get_ia_by_id($dec_info->prop_id)->result(),
    'ib' => $this->Model_admin->get_ib_by_id($dec_info->prop_id)->result(),
    'ii' => $this->Model_admin->get_ii_by_id($dec_info->prop_id)->result(),
    'iiia' => $this->Model_admin->get_iiia_by_id($dec_info->prop_id)->result(),
    'iiib' => $this->Model_admin->get_iiib_by_id($dec_info->prop_id)->result()
    );

    $data_applicant = array(
            // get data using email
    'token' => $token,
    'applicant_info' => $this->model->getApplicantInfo($this->session->userdata('email'))->row(),
    'dec_info' => $dec_info,
    'ia' => $this->Model_admin->get_ia_by_id($dec_info->prop_id)->result(),
    'ib' => $this->Model_admin->get_ib_by_id($dec_info->prop_id)->result(),
    'ii' => $this->Model_admin->get_ii_by_id($dec_info->prop_id)->result(),
    'iiia' => $this->Model_admin->get_iiia_by_id($dec_info->prop_id)->result(),
    'iiib' => $this->Model_admin->get_iiib_by_id($dec_info->prop_id)->result()
    );


    if ($this->session->userdata('position_id') == '2') { // Administrator
        $this->load->view('includes/admin_header', $data_admin);
        $this->load->view('applicant/properties/view_new_declaration_1', $data_admin);
    }
    if ($this->session->userdata('position_id') == '3') { // Applicant
        $this->load->view('includes/admin_header', $data_applicant);
        $this->load->view('applicant/properties/view_new_declaration_1', $data_applicant);
    }
     else {
        $this->logout();
    }
}

我只是CodeIgniter的新手 请帮忙。我好绝望。先感谢您 想显示以下信息,但显示错误消息 我该怎么办?

1 个答案:

答案 0 :(得分:0)

一开始也让我感到困惑。

要做:

public function view_new_declaration_1($id=null,$token=null){

这样,如果用户访问somesite.com/view_new_declaration_1而没有somesite.com/view_new_declaration_1/someid/sometoken,您将不会得到太多错误。

话虽如此,您仍然应该按照以下方式检查代码中是否存在这些参数,因为它们似乎是必需的

public function view_new_declaration_1($id=null,$token=null){
    if (is_null($id) || is_null($token)) {
        show_error('Missing parameters'); // exits
    }
    ...
}