By default, URLs in CodeIgniter are designed to be search-engine and human friendly. Rather than using the standard "query string" approach to URLs that is synonymous with dynamic systems, CodeIgniter uses a segment-based approach: example.com/news/article/my_article
CodeIgniter URLs can be simplified a number of ways, either via helpers, or routing.
URL Helper
Makes your life easier by bringing functionality to your fingertips without typing out lengthy repetitious urls or anchor code. Things like:
- site_url()
- base_url()
- current_url()
- anchor() ouputs something like
<a href="http://example.com">Click Here</a>
- and more...
Routes
Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:
example.com/class/function/id/
However you may want something crazy like this:
example.com/page/when-i-use-php-i-sneeze/12/4/2011/bob
Routes help you achieve that and still point to the proper class/method in an example like so:
$route['product/:num'] = "catalog/product_lookup";
You can match literal values or you can use two wildcard types:
- (:num) will match a segment containing only numbers.
- (:any) will match a segment containing any character.