PHP Luminova: URL Path Structure and Segmentation
View Segments is a utility class designed to assist in accessing requested view URIs, simplifying processing tasks.
View Segments" is a utility class designed to simplify the retrieval of specific segments from requested view URIs. It offers methods that allow easy access to different parts of the URI, making it convenient to extract and process relevant information.
- Class namespace:
\Luminova\Routing\Segments
Usage in your controller class.
$segment = $this->app->router->getSegment();Usage in routing context file /routes/my-context.php;
$segment = $router->getSegment();Methods
index
Retrieve the view URI segment by index position.
public index(int $index): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$index | int | Position index to return segment. |
Return Value:
string - View segment
Example
https://example.com/page/foo/bar/baz
echo $segment->index(1);
// foofirst
Retrieve the first segment of the current view URI.
public first(): stringReturn Value:
string - First URI segment
Example
https://example.com/page/foo/bar/baz
echo $segment->first();
// pagecurrent
Retrieve the last segment of the current view URI.
public current(): stringReturn Value:
string - Current URI segment.
Example
https://example.com/page/foo/bar/baz
echo $segment->current();
// bazprevious
Retrieve the view segment before the last segment.
public previous(): stringReturn Value:
string - The segment before the last.
Example
https://example.com/page/foo/bar/baz
echo $segment->previous();
// barsegments
Retrieve the current view segments as an array.
public segments(): array<int,string>Return Value:
array - Array list of URL segments.