Welcome Guest, Not a member yet? Register   Sign In
URI Routing, How to pass ID into method?
#1

[eluser]TomRPS[/eluser]
The docs show this example route:
Code:
$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";

I have been trying to use this example to test how to get an ID into a method. So far nothing has worked.
In the example it has "$1" which I assume is supposed to be the ID. Is this correct and does it have to be $1 or can it be something else?

What do I put in my method's parameter? In the case of the above route a request to http://mysite.com/product/4323 would be routed to catalog.php and product_lookup_by_id method

So if I have the method:

Code:
public function product_lookup_by_id($id)
{
    echo $id;
}

Does the name of the parameter ($id in this case) matter? If so what should it be. When I use the code above all I get is a blank page.
#2

[eluser]hsn22[/eluser]
i'm pretty new to CI myself, so this may not be the optimal solution/answer.

try to get the id through this method:

Code:
$this->uri->rsegment(n)

where n would be 3 for your case.




Theme © iAndrew 2016 - Forum software by © MyBB