segment($n[, $no_result = NULL])
Parameters: |
|
---|---|
Returns: |
Segment value or $no_result value if not found |
Return type: |
mixed |
Permits you to retrieve a specific segment. Where n is the segment number you wish to retrieve. Segments are numbered from left to right. For example, if your full URL is this:
http://example.com/index.php/news/local/metro/crime_is_up
The segment numbers would be this:
- news
- local
- metro
- crime_is_up
The optional second parameter defaults to NULL and allows you to set the return value of this method when the requested URI segment is missing. For example, this would tell the method to return the number zero in the event of failure:
$product_id = $this->uri->segment(3, 0);
It helps avoid having to write code like this:
if ($this->uri->segment(3) === FALSE) { $product_id = 0; } else { $product_id = $this->uri->segment(3); }
Please login to continue.