Mohammad Sulaiman
Mohammad Sulaiman

Reputation: 21

Yii2 class Yii/web/UrlManager causes error

I have urlManager like this in web.php

        'urlManager' => 
    [
        //'class' => 'yii/web/UrlManager',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'enableStrictParsing' => false,
        'rules' => 
        [
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        ],
    ],

I just wanna know, why if I uncomment 'class' => 'yii/web/UrlManager', will cause error when I run my website.

Thank You so much

Upvotes: 0

Views: 367

Answers (2)

israr
israr

Reputation: 1175

Your Class path from

Url manager

is not correct. Yii work with namespace and to use namespace always use backslash \ instead of front slash /. So your code should be in following format:

 'class' => 'yii\web\urlManager',

Instead of

'class' => 'yii/web/UrlManager',

Upvotes: 2

Irfan Ali
Irfan Ali

Reputation: 2258

UrlManager path is wrong. why because this should be like namespace.

yii/web/UrlManager

instead of this, try this.

yii\web\UrlManager

Note:- it's back slash not front slash.

Upvotes: 1

Related Questions