Welcome Guest, Not a member yet? Register   Sign In
URI Routing Help
#1

[eluser]beerguide_au[/eluser]
I am currently working on an application which has the following requirements:

URI must be in the format /product-reviews/company-name/product-name (or if a direct review id is known) /product-reviews/company-name/product-name/review-id

I wrote the following route in route.php (config)
$route['product-reviews/:any/:any'] = 'productreviews/review_lookup/$1/$2';

Which as I understand will call the productreviews class, and then the review_lookup function and pass that function the parameters from the :any (ie: $1 and $2).

My problem is when echo'ing out the parameters on my view I simply get a "$1".

My controller code is:
Code:
function review_lookup( $company_name, $product_name ) {
        // $this->load->view('productreviews_view', $data );
        $data['company_name'] = $this->uri->rsegment(3);
        $data['product_name'] = $this->uri->rsegment(4);
        
        $this->load->view('productreviews_view', $data );
    }

My view code is simply:
Code:
<?php
echo $product_name;
?>

Im assuming my controller and views are all hooked up correctly as its loading the correct function and view, just displaying the wrong data.

Is it my routing rules that are wrong, or the way I'm calling it/them from the controller?

Thanks in advance for anyone that can help.
#2

[eluser]fdog[/eluser]
Try escaping the $ in the route.
#3

[eluser]beerguide_au[/eluser]
Nope, that didn't fix it.

I just tried (.+)* instead of :any as a last ditch effort which has fixed it.

My issue is now resolved, but begs the question - why doesn't :any work with $1 ?
#4

[eluser]Pascal Kriete[/eluser]
If I remember correctly you still have to define also define a capturing group when using :num or :any.

So it would be $route[’product-reviews/(:any)/(:any)’] = ‘productreviews/review_lookup/$1/$2’;
#5

[eluser]beerguide_au[/eluser]
Bingo! Thats it.

Thanks for the follow up inparo!
#6

[eluser]sophistry[/eluser]
yeah, the user manual gives an example with :any without clarifying that point. i made a feature request with that and the option to have $0 have the full capturing pattern.

http://ellislab.com/forums/viewthread/70410/




Theme © iAndrew 2016 - Forum software by © MyBB