1

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 !

Prakash Pazhanisamy
  • 997
  • 1
  • 15
  • 25
Samaël Villette
  • 318
  • 3
  • 25
  • 1
    see this http://blog.neattutorials.com/seo-friendly-urls-in-yii2/, OR http://stackoverflow.com/questions/26525320/enable-clean-url-in-yii2 – GAMITG Apr 21 '16 at 08:50
  • I think, it is necessary to clarify, that you're talking about ALL parameters (including those of it, that can be non-described in url rule). Because the only way that I know - to describe it in url rule or create custom UrlRule Class, implementing createUrl() method – Akim Kelar Apr 21 '16 at 09:47

2 Answers2

1

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>'
Prakash Pazhanisamy
  • 997
  • 1
  • 15
  • 25
0

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) {}

StalkAlex
  • 743
  • 7
  • 16