I am doing a project that when click the 'submit order' button, it will redirect to a successful message page. And the URL is [http://example.com/index.php/Ordering/Order] but I want the URL looks like [http://example.com/index.php/Ordering/Order/1], the number[1] is the id for order which is retrieve from database. Hope someone can helps me. Thank You.
Route.php:
$route['Ordering/Order/(:num)'] = 'Ordering/IdForRoute/$1';
Controller:
public function IdForRoute(){
$data['id'] = $this->order->GetId($id);
if (this->uri->segment(3) === FALSE){
$data['id'] = 0;
} else{
$data['id'] = $this->uri->segment(3);
}
}
Model:
public function GetId($id = 0){
if ($id === 0) {
$query = $this->db->get('order');
return $query->result_array();
}
$query = $this->db->get_where('order', array('id' => $id));
return $query->row_array();
}