0 follower

Final Class Yiisoft\Yii\DataView\YiiRouter\UrlParameterProvider

InheritanceYiisoft\Yii\DataView\YiiRouter\UrlParameterProvider
ImplementsYiisoft\Yii\DataView\Url\UrlParameterProviderInterface

Provider for accessing URL parameters from both path and query string.

Public Methods

Hide inherited 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

Hide inherited methods

__construct() public method

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) {}

            
get() public method

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, null otherwise. For query parameters, only string values are returned; other types result in null.

                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,
    };
}