2

我正在尝试将多个参数从我的控制器传递给我的模型。在我提交表单后,我试图传递的似乎$scholId不会通过模型。但是,$userId通过数据库就好了。有什么问题$this->uri->segment(4)不能正确通过吗?

function apply() 
{
    $this->load->helper('form');
    $this->load->library('form_validation');

    $scholId = $this->uri->segment(4);

    $userId = '2'; //User query -> this will be taken from session

    $this->data['scholarship'] = $this->scholarship_model->getScholarship($scholId);
    $this->data['title'] = "Apply";

    $this->form_validation->set_rules('essay', 'Essay', 'required');

    if ($this->form_validation->run() === FALSE)
    {
        $this->load->view('templates/header', $this->data);
        $this->load->view('student/page_head', $this->data);
        $this->load->view('student/form', $this->data);
        $this->load->view('templates/footer', $this->data);
    }else{
        // Validation passes
        $this->users_model->applySchol($userId,$scholId);
        redirect('/scholarships');
    }
}
4

1 回答 1

1

您需要在传递之前检查该段是否存在,例如:

if ($this->uri->segment(4) === FALSE)
{
    $schoId = 0; //or anything else so that you know that does not exists
}
else
{
    $schoID= $this->uri->segment(4);
}

或者简单地说:

$product_id = $this->uri->segment(4, 0);
//which will return 0 if it doesn't exists.
于 2013-01-10T21:18:57.037 回答