2

I am trying to pass multiple parameters to my model from my controller. It seems that the $scholId that I am trying to pass won't go through to the model after I submit the form. However, the $userId goes through to the database just fine. Is there something wrong with $this->uri->segment(4) that won't pass through correctly?

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');
    }
}
3
  • when you submit the form segment will not have any value Commented Jan 10, 2013 at 20:17
  • can you do var_dump($schoId) before submitting and post it here? Commented Jan 10, 2013 at 21:11
  • Make sure you're getting the right segment. Controller is 1, function is 2 etc. Don't count the base url (sort of obvious I suppose) Can you show an example URL that isn't working? Do what mamdouh said dump it out, if it isn't returning what you think or anything try changing it to 3. Commented Jan 10, 2013 at 23:24

1 Answer 1

1

you need to check up the segment whether it exists or not before passing it Like:

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);
}

or simply:

$product_id = $this->uri->segment(4, 0);
//which will return 0 if it doesn't exists.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.