Final Class Yiisoft\Yii\DataView\YiiRouter\UrlParameterProvider
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Provider for accessing URL parameters from both path and query string.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Creates a new URL parameter provider instance. | Yiisoft\ |
| get() | Gets a URL parameter value by name and type. | Yiisoft\ |
Method Details
Creates a new URL parameter provider instance.
| public mixed __construct ( \ | ||
| $currentRoute | \ |
The current route service used to access route arguments. |
public function __construct(private readonly CurrentRoute $currentRoute) {}
Gets a URL parameter value by name and type.
This method can retrieve parameters from:
- Path: Using route arguments (e.g., /users/{id}/profile)
- Query: Using $_GET parameters (e.g., ?sort=name)
| public string|null get ( string $name, \ | ||
| $name | string |
The parameter name to retrieve. |
| $type | \ |
The parameter type. |
| return | string|null |
The parameter value if found, |
|---|---|---|
public function get(string $name, UrlParameterType $type): ?string
{
return match ($type) {
UrlParameterType::Path => $this->currentRoute->getArgument($name),
UrlParameterType::Query => (isset($_GET[$name]) && is_string($_GET[$name])) ? $_GET[$name] : null,
};
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.