D
D
Doniyor Mamatkulov2016-11-28 09:26:28
Yii
Doniyor Mamatkulov, 2016-11-28 09:26:28

CNC not working on Yii2?

Hi all! In my project on Yii2, I implemented user-friendly (NC) links, as described in the article here . In the database I write alias: 'test-alias.html', and in the route I write 'site/about' and everything works with a bang. But if you write a route like 'category/2' in the database, the CNC link is not formed (it just goes to mysite.com/ru/category/2).
My link is formed like this: and in the UrlManager there is a rule: How to make it so that when you click on a link like "category / 2", the link is formed and opened by the CNC?
Url::to(['category/view', 'id' => $hit->id])
'category/<id:\d+>' => 'category/view',

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2016-11-28
@matios

in UrlManager
link like this

Url::to(['category/view', 'alias' => $hit->alias]); //так
Yii::$app->urlManager->createUrl(['category/view', 'alias' => $hit->alias]); //или так

In the category/view action, catch the GET parameter ALIAS and use this alias to search for an article in the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question