Yii2 How to change route from foo-bar to foo_bar

I've the controller function named like actionFooBar()

I can access with index.php?r=class/foo-bar

If I want to change to available with url like index.php?r=class/foo_bar

How can I do this ?

Upvotes: 1

Views: 65

Answers (2)

joshua pogi 28
joshua pogi 28

Reputation: 532

foo-bar actually the action is actionFooBar

to change it to foo_bar make it actionFoo_bar

and if you use pretty url add route rules

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

to accept special characters.

Upvotes: 2

I can done this by change function name to actionFoo_bar()

Now I can access to index.php?r=class/foo_bar

Does not sure that their are another solution or not?

Upvotes: 0

Related Questions