D
D
Doniyor Mamatkulov2016-11-30 11:18:22
Yii
Doniyor Mamatkulov, 2016-11-30 11:18:22

UrlManager rule for text ids?

Hey!
Yii2 project. I create a link like this:

<a href="<?= Url::to(['category/view', 'alias' => 'the-test-alias.html'])?>" title="">Some link</a>
As a result, a link of the form is formed:
http://mywebsite.com/ru/category/view?alias=the-test-alias.html

Question: how to write a rule in UrlManager so that the link is formed like this:http://mywebsite.com/ru/the-test-alias.html

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2016-11-30
@doniyorbekm

'<alias:\w+>' => 'category/view',
UPD: according to your comment, the rule does not work because you incorrectly form the URL
Why is there html? Are you trying to add the html suffix to the link? then you should use the suffix parameter in UrlManager
For example:

'UrlManager' => [
    'suffix' => '.html'
]

Url::to(['category/view', 'alias' => 'the-test-alias'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question