Answer the question
In order to leave comments, you need to log in
Using the name property of the UrlManger::rules parameter in the Url helper. How and is it possible?
Hello.
There is a config
...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => require 'routes.php',
],
...
return [
[
'name' => 'cat',
'pattern' => 'cat/<slug:.+>',
'route' => 'category/index',
'suffix' => '/',
],
[
'name' => 'pst',
'pattern' => 'post/<id:\d+>-<slug:.*>',
'route' => 'post/post',
'suffix' => '.html',
],
];
echo Url::to(['cat', 'slug' => $this->slug]);
echo Url::to(['pst', 'id' => $this->id, 'slug' => $this->slug]);
echo Url::to(['category/index', 'slug' => $this->slug]);
echo Url::to(['post/post', 'id' => $this->id, 'slug' => $this->slug]);
Answer the question
In order to leave comments, you need to log in
Create your own url helper, inherit from the base one, replace it. Use your
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question