The documentation gives some example code, but it doesn’t say where to put it.
The documentation gives some example code, but it doesn’t say where to put it.
In your routes config.
Take a look here:
A rule can be either a string or an array or an instance of UrlRuleInterface.
Do you know the exact syntax? I’ve been trying to get it to work but no luck.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
new \yii\web\GroupUrlRule([
'prefix' => 'test',
'rules' => [
'about' => 'site/about',
],
])
],
],
Gives error:
PHP Warning – yii\base\ErrorException
trim() expects parameter 1 to be string, object given
Since the key-value loop is used there, I’d guessed something like
'rules' => [
'myGroupRule' => new \yii\web\GroupUrlRule([
'prefix' => 'test',
'rules' => [
'about' => 'site/about',
],
])
],
Nope same error - in vendor\yiisoft\yii2\web\UrlRule.php line 149.
With the latest code, the code should be fine. If you are using beta code, you should use
'rules' => [
[
'class' => 'yii\web\GroupUrlRule',
'prefix' => 'test',
'rules' => [
'about' => 'site/about',
],
]
],
Worked perfect, thanks!