Final Class Yiisoft\Yii\DataView\YiiRouter\UrlParameterProvider
| Inheritance | Yiisoft\Yii\DataView\YiiRouter\UrlParameterProvider |
|---|---|
| Implements | Yiisoft\Yii\DataView\Url\UrlParameterProviderInterface |
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\Yii\DataView\YiiRouter\UrlParameterProvider |
| get() | Gets a URL parameter value by name and type. | Yiisoft\Yii\DataView\YiiRouter\UrlParameterProvider |
Method Details
Creates a new URL parameter provider instance.
| public mixed __construct ( \Yiisoft\Router\CurrentRoute $currentRoute ) | ||
| $currentRoute | \Yiisoft\Router\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, \Yiisoft\Yii\DataView\Url\UrlParameterType $type ) | ||
| $name | string |
The parameter name to retrieve. |
| $type | \Yiisoft\Yii\DataView\Url\UrlParameterType |
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,
};
}
Signup or Login in order to comment.