2013-01-10 123 views
2

我想從控制器傳遞多個參數到我的模型。看起來,我正在嘗試通過的$scholId在我提交表單後不會通過模型。但是,$userId只能通過數據庫。 $this->uri->segment(4)有什麼問題不能正確傳遞?Codeigniter - 傳遞多個參數

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'); 
    } 
} 
+0

當您提交表單段將不會有任何值 –

+0

您可以在提交之前做var_dump($ schoId)並將其發佈到此處嗎? –

+0

確保您獲得了正確的細分。控制器是1,功能是2等。不計算基地網址(顯然我認爲這種排序)你可以顯示一個示例URL不工作?做什麼mamdouh說轉儲它,如果它沒有返回你的想法或任何嘗試將其改爲3。 –

回答

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.