Codeigniter-传递多个参数

Codeigniter-传递多个参数,codeigniter,Codeigniter,我试图从控制器向模型传递多个参数。在我提交表单后,我试图通过的$scholId似乎不会进入模型。但是,$userId可以很好地进入数据库。$this->uri->segment(4)是否存在无法正确通过的错误 function apply() { $this->load->helper('form'); $this->load->library('form_validation'); $scholId = $this->uri->s

我试图从控制器向模型传递多个参数。在我提交表单后,我试图通过的
$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');
    }
}

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

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.

当您提交表单段时,表单段将没有任何值。您可以在提交表单段之前进行var_dump($schoId)并将其发布到此处吗?确保您获得了正确的表单段。控制器是1,函数是2,等等。不要计算基本url(我想有点明显),你能给出一个不工作的示例url吗?按照mamdouh说的做,把它扔掉,如果它没有返回你的想法或任何东西,试着把它改成3。