Hi looking for some help. I recently started coding with Codeigniter.
I have 2 functions within the same controller. I need 'uri segment' from first function to second. Tried to google but no success.
Here is my controller:
public item_page() {
$id = $this->uri->segment(3);
$this->load->view('view');
}
public validation() {
// Form Validation Goes Here
if($this->form_validation->run() == FALSE) {
$this->session->set_userdata('validation_errors', validation_errors());
redirect('item-page/'.$id); // I need variable here
} else {
redirect('execute');
}
}
you can some Attribute in your class(controller)
controller:
private $page_id;
public item_page() {
$id = $this->uri->segment(3);
$this->page_id=$id;
$this->load->view('view');
}
public validation() {
// Form Validation Goes Here
if($this->form_validation->run() == FALSE) {
$this->session->set_userdata('validation_errors', validation_errors());
redirect('item-page/'.$this->page_id); // I need variable here
} else {
redirect('execute');
}
}
////// Method 2:
public item_page() {
$id = $this->uri->segment(3);
$this -> session -> set_userdata('id', $id);
$this->load->view('view');
}
public validation() {
// Form Validation Goes Here
if($this->form_validation->run() == FALSE) {
$this->session->set_userdata('validation_errors', validation_errors());
redirect('item-page/'.$this -> session -> userdata("id")); // I need variable here
} else {
redirect('execute');
}
}
hope this help.