ishtiaq ahmed
ishtiaq ahmed

Reputation: 495

Getting error Invalid Call – yii\base\InvalidCallException when customizing urlManager component in Yii 2

I have set up the Yii 2 basic app and under config/web.php I use:

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

under components.

But when I try to run my application, I get the following error:

Invalid Call – yii\base\InvalidCallException Setting read-only property: yii\web\Application::urlManager>

Same urlManager code works fine in advanced app though. Any ideas why?

Upvotes: 3

Views: 6234

Answers (3)

Ashish
Ashish

Reputation: 1

Please use this sequence

'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'mailer'=>[
        'class'=>'yii\swiftmailer\Mailer',
        'useFileTransport'=> false,
        ],
        'authManager'=>
        [
            'class'=>'yii\rbac\DbManager',
            'defaultRoles'=> ['guest'],
        ],

Upvotes: 0

sunrain
sunrain

Reputation: 31

The following is the correct configuration.

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

Upvotes: 2

Victor Wong
Victor Wong

Reputation: 2486

Invalid Call – yii\base\InvalidCallException Setting read-only property: yii\web\Application::urlManager>

From this error message, it looks like that you are trying to redefine urlManager in the Application component which is not allowed.

urlManager, and several other components such as security are predefined as core application component. Most probably, redefining these core components will cause unexpected behavior (though I have not witnessed any).

Try removing the key class in the configuration.

'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
    ]

Upvotes: 5

Related Questions