CodeIgniter Forums
A problem with routing (multiple wildcards?) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: A problem with routing (multiple wildcards?) (/thread-2743.html)



A problem with routing (multiple wildcards?) - El Forum - 08-22-2007

[eluser]#1313[/eluser]
Hello everybody, another newbie coming up!

My site has a cars catalogue, and i want to produce following URIs for my cars:
Code:
http://site.com/cars/lamborgini
and for specific models:
Code:
http://site.com/cars/lamborgini/murcielago

I have following functions in my Cars controller, car_maker() and car_model(), and a simple rule in routes.php:
Code:
$route['cars/:any'] = "cars/car_maker";
which succesfully sends control to car_maker function. Great, i can read about Lamborginis.

But now i want to read a page about Lamborgini Murcielado. I want to add a routing rule to launch car_model function, but i don't know how to write a rule with multiple wildcard characters properly. I tried
Code:
$route['cars/:any/:any'] = "cars/car_maker/car_model";
but this isn't working. How do i do this?


A problem with routing (multiple wildcards?) - El Forum - 08-22-2007

[eluser]#1313[/eluser]
Whoops, i solved this question by myself =)

Code:
$route['cars/([a-z_\-]+)/(.+)'] = "cars/car_model/$1/$2";
$route['cars/:any'] = "cars/car_maker";

Worked perfectly.