Chhorn Soro
Chhorn Soro

Reputation: 3141

Accept String Parameter in Yii2 Action

In my config file I've set the url rule like this :

<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>

And what happens is:-

controller/action/123 (work)
controller/action/hello (not work)

But it accepts only digit as the parameter.
What I want is that both digit and string should be accepted.

Please help!!!!

Upvotes: 1

Views: 1567

Answers (1)

Murray Foxcroft
Murray Foxcroft

Reputation: 13745

The d+ pattern matches numbers 0-9, so it is working as expected. Change the regex pattern to match strings. Try w+.

Change:

<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>

To:

<controller:\w+>/<action:\w+>/<id:\w+>' => '<controller>/<action>

Upvotes: 2

Related Questions