sorry to bother but I was hoping someone could help me out with a quite mundane issue that I am having within CI. I am able to send a variable via the URL using CI's examples eg:
http://localhost/project/main/getproduct/24
within the getproduct() method of my main controller I can get the variable sent 24, without an issue.
however I now want to pass two variables via the URL, but I have no idea how to do this or whether CodeIgniter will allow me to do this. could someone please show me how to pass 2 variables in CI and a method that can retrieve them I have tried:
http://localhost/project/main/getproduct/24/45
and then within my getproduct method:
public function getproduct($productID, $factoryID){
.....
}
but I'm finding my method can get the first variable without an issue but not the second variable. Could anyone point me in the right direction please. Many thanks in advance.
Solution of this problem is using of _remap() function. You just need to add this function before index() function
I hope this will solve your problem.
If someone else runs into this using CI3. In CodeIgniter 3 no special route is needed. Not sure if it also works on CI2 now.
You can access those URI segments using parameters just like that:
You can use
uri
to retrieve values in your urlHere is an example
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:
Then i hope it will work.
Passing URI Segments to your methods
If your URI contains more than two segments they will be passed to your method as parameters.
For example, let’s say you have a URI like this:
Your method will be passed URI segments 3 and 4 (“sandals” and “123”):
Important!!! If you are using the URI Routing feature, the segments passed to your method will be the re-routed ones.
Refer to this link as Codeigniter Official Guide. Codeigniter Official Guide.
http://example.com/project/main/getproduct/24/45
To get '45', you can do this: