I'm new in Yii2 framework and I didn't understand how rules in urlManager work.
I have my url controller/action?id=1
and I want controller/action/id/
or controller/action/1
. How can I do that with url management ?
Thanks !
I'm new in Yii2 framework and I didn't understand how rules in urlManager work.
I have my url controller/action?id=1
and I want controller/action/id/
or controller/action/1
. How can I do that with url management ?
Thanks !
If your argument is number then use this rule:
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>'
If your argument is text then use this rule:
'<controller:\w+>/<action:\w+>/<name:\w+>' => '<controller>/<action>'
You can use regular expressions in rules array.
This is example
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>'
Then in your controller you will get id like this
public function actionTest($id) {}