S
S
serikd2016-03-23 15:19:51
Yii
serikd, 2016-03-23 15:19:51

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',

        ],
...

In the routes.php file respectively
return [
    [
        'name' => 'cat',
        'pattern' => 'cat/<slug:.+>',
        'route' => 'category/index',
        'suffix' => '/',
    ],

    [
        'name' => 'pst',
        'pattern' => 'post/<id:\d+>-<slug:.*>',
        'route' => 'post/post',
        'suffix' => '.html',
    ],
];

How (if possible) to use the name of the rule instead of route in the Url helper?
Example
echo Url::to(['cat', 'slug' => $this->slug]);
echo Url::to(['pst', 'id' => $this->id, 'slug' => $this->slug]);

Instead of
echo Url::to(['category/index', 'slug' => $this->slug]);
echo Url::to(['post/post', 'id' => $this->id, 'slug' => $this->slug]);

For example in routes.php I changed the route or changed the action in the controller and not to make changes in all Url::to();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-03-23
@serikd

Create your own url helper, inherit from the base one, replace it. Use your

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question