K
K
Kristo Negri2014-11-28 17:21:02
Yii
Kristo Negri, 2014-11-28 17:21:02

How to change ID to slug/alias in url in Yii2?

There is a good article, habrahabr.ru/post/208328/, where the author describes the method for creating slugs, everything is clear, but how can I change the ID in the url to slug?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Timofeev, 2014-12-04
@webinar

Do you mean address domain/controller/id to domain/controller/sometext?
I decided by changing the urlmanager
on the
'<controller:\w+>/<id>' => '<controller>/view',

D
Denis Skripchenko, 2016-04-06
@dskripchenko

'<controller:\w+>/key/<key:[\w+-]*\w+>/?'=>'<controller>/view'

public function actionView($key = null){
...
}

'<controller:\w+>/key/<key:[\w+-]*\w+>/?/product/<product:[\w+-]*\w+>/?'=>'<controller>/view'

public function actionView($key = null,$product = null){
...
}

K
Kristo Negri, 2014-12-04
@EndErr

Yes, exactly like that

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question