P
P
Pavel Gogolinsky2014-11-09 01:30:18
Yii
Pavel Gogolinsky, 2014-11-09 01:30:18

How to configure urlManager in Yii2 to work with modules?

There is a Product module. It contains a Backend controller for editing catalog products. Also in the app/controllers folder there is a ProductController controller with an actionIndex to display products. When I go to site.ru/product/index, I get 404. I realized that Yii is trying to find the Index controller in the Product module.
How to configure UrlManager (CNC) so that it would first search for controllers in the controllers folder, and only then climb into the modules?
"As before" doesn't help.

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dialog, 2014-11-09
@Dialog

PrettyUrl specified? Some kind of suffix, hiding the script display?
Try this:

'urlManager' => [
    'enablePrettyUrl' => true,
    'enableStrictParsing' => false,
    'showScriptName' => false,
    'rules' => [
        '<controller>/<action>' => '<controller>/<action>',
        '<module>/<controller>/<action>' => '<module>/<controller>/<action>',
    ],
],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question