Getting Invalid Call error - yii \ base \ InvalidCallException while configuring urlManager component in Yii 2
I have installed a basic Yii 2 application and am config/web.php
using:
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>
The same urlManager
code works fine in an extended app. Any ideas why?
source to share
Invalid Call – yii\base\InvalidCallException Setting read-only property: yii\web\Application::urlManager>
From this error message, it looks like you are trying to override urlManager
in the Application component, which is not allowed.
urlManager
and some other components like security
are predefined as main application component. Chances are, overriding these core components will cause unexpected behavior (although I haven't seen it yet).
Try to remove the key class
in the config.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
]
source to share
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'],
],
source to share