Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wildcards to use in codeigniter routing?

in codeigniter you can use wildcard to reroute.

i never heard the word wildcards before.

is this a set of rules you can use like regexp?

cause in codeigniter documentation they just gave some examples eg.

$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";

is there a list/reference with all the available wildcard expressions you can use?

like image 785
never_had_a_name Avatar asked Apr 10 '10 08:04

never_had_a_name


People also ask

What is wildcards in routing?

A Wildcard route has a path consisting of two asterisks (**). It matches every URL, the router will select this route if it can't match a route earlier in the configuration. A Wildcard Route can navigate to a custom component or can redirect to an existing route.

How does route work in CodeIgniter?

Routing matches the URL to the pre-defined routes. If no CodeIgniter Route match is found then, CodeIgniter throws a page not found an exception. CI Routing is responsible for responding to URL requests. Routing matches the URL to the pre-defined routes.

What is routing in CodeIgniter?

Routing rules are defined in your application/config/routes. php file. In it you'll see an array called $route that permits you to specify your own routing criteria. Routes can either be specified using wildcards or Regular Expressions.

What is default controller in CodeIgniter?

Defining a Default ControllerCodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes. php file and set this variable: $route['default_controller'] = ' Blog ';


1 Answers

You can match literal values or you can use two wildcard types:

:num
:any

:num will match a segment containing only numbers.
:any will match a segment containing any character.

Or you can use your custom regex, example:

$route['products/([a-z]+)/(\d+)'] = "$1/id_$2";
like image 177
Sarfraz Avatar answered Sep 29 '22 12:09

Sarfraz