Urlmanager with modules not working in yii2.0

This is about creating a module inside the backend folder. For example, I created the module name as "api". And also successfully created a controller for these modules.

here is my urlmanager code:

  'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'rules' => [

                '<module:\w+>/<controller:\w+>/<action:\w+>'=>'<module>/<controller>/<action>',
                '<module:\w+><controller:\w+>/<action:update|delete>/<id:\d+>' => '<module>/<controller>/<action>',

            ],
        ]

      

when i access url relative to module as "api", controller as "country" and action as "create"

http://local2host.com/bootstrap/backend/web/index.php/api/country/create it shows 404 Not Found error

Where am I going wrong?

+3


source to share


2 answers


The second rule will never work. Also you don't need to define rules and normal ones will work. So this is

'urlManager' => [
    'class' => 'yii\web\UrlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
],

      



will make this link /website.com/core/contact/index just fine.

But I'm not sure why your route didn't catch the first rule ... weird. It should be.

+2


source


Better late and then never.

For the make module to work, you need to add it to config:



'modules' => [
......
    'modulename' => [
        'class' => 'app\modules\modulename\Module',
    ],
......
],

      

0


source







All Articles