Passing multiple variables in URL using codeigniter Passing multiple variables in URL using codeigniter codeigniter codeigniter

Passing multiple variables in URL using codeigniter


The accepted answer will work for this particular issue, but will not work if the url ever changes. To access multiple variables in your controller, simply add to the function definition.

http://localhost/project/main/getproduct/24/45

class Main extends CI_Controller {    public function getproduct($productID = 0, $factoryID = 0)    {      // ProductID will be 25      // Factory ID will be 45    }}

Reference: CodeIgniter User Guide


You can use uri to retrieve values in your url

Here is an example

public function getproduct(){  $productID =  $this->uri->segment(3);  $factoryID =  $this->uri->segment(4);  // ProductID will be 25  // Factory ID will be 45}

Then you can just use the values as you please


You must set a route in config/routes.php to parse the items.

It looks like:

   $route["getproduct/(:any)/(:num)"]="main/changequestion/$1/$2"

Then i hope it will work.