Exchanging URL Parameters

my current url is http: // localhost / ci / test_test / test / 12 / abc

12 is my id and abc is the value to be passed in the function test

now I want my url to look like this http: // localhost / ci / test_test / test / id / 12 / val / abc the function can know that after the id keyword its id and after the value keyword its value

public function test($id="",$code=""){ 
        $data['id']=$id;
        $data['code']=$code;
		$this->load->view('welcome_message',$data);
	}
      

Run codeHide result


+3


source to share


1 answer


In your route.php specify your url like this:

$route['test_test/test/id/(:num)/val/(:any)'] = "path/to/your_controller/$1/$2";

      



and your controller:

public function your_controller($id="",$val){
    //...
}

      

+5


source







All Articles