M
M
Mark2018-03-11 07:55:45
Yii
Mark, 2018-03-11 07:55:45

How to remove "default" from Yii2 module for DefaultController only?

Hello. The task is to remove "/default/" from the DefaultController URL, i.e. so that the path like "/ticket/default/new" becomes "/ticket/new". To do this, I use the solution with urlManager:

'<module:\w+>/<action:\w+>/<id:(.*?)>' => '<module>/default/<action>',
    '<module:\w+>/<action:\w+>' => '<module>/default/<action>',
    '<module:\w+>' => '<module>/default/index',

But the problem is that the rule applies to all controllers, not just those that are default controllers. Those. when trying to go to "profile/settings/change-password" - 404 is returned. I tried to replace "default" with " <controller>" in the rules - it did not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-03-11
@slo_nik

Good morning.
Try like this

'<_m:[\w\-]+>' => '<_m>/default/index',
'<_m:[\w\-]+>/<_c:[\w\-]+>' => '<_m>/<_c>/index',
'<_m:[\w\-]+>/<_a:[\w\-]+>/<id:\d+>' => '<_m>/default/view',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<_a:[\w\-]+>' => '<_m>/<_c>/<_a>',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<id:\d+>/<_a:[\w\-]+>' => '<_m>/<_c>/<_a>',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question