Yii2 Setting read-only property: yii\web\Application::log

Hi,
I’m using the Advanced template (locally with XAMPP) and have added an API entry point at the same level as backend and frontend.

Both backend.test and front.end bring up their respective Login pages. However, when I trigger the API part i get:

Invalid Call – [yii\base\InvalidCallException](http://www.yiiframework.com/doc-2.0/yii-base-invalidcallexception.html)
Setting read-only property: yii\web\Application::log

My main.php in api/config is:

<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    //require __DIR__ . '/params-local.php'
);

//$db = require __DIR__.'/../../common/config/main-local.php';

return [
    'id' => 'app-api',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'api\controllers',
    //'controllerNamespace' => 'api\modules\v1\controllers',
    'defaultRoute' => 'default',
    'bootstrap' => ['log'],
    'modules' => [
        'v1' => [
            'basePath' => '@api/modules/v1',
            'class' => 'api\modules\v1\Module',
            ],
        'v2' => [
            //'basePath' => '@app/modules/v2',
            'class' => 'api\modules\v2\Module',
            ],
        ],
    'components' => [
        //'response' => [
        //    'format' => 'yii\web\Response::FORMAT_JSON',
        //],
        'request' => [
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
                ],
        'enableCsrfValidation' => false,
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => false,
        ],
    ],
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
                //'logFile' => '@api/runtime/apilog.txt',
            ],
        ],
    ],
    'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,
        'rules' => [
            [
                ['' => 'default'],
                ['class' => 'yii\rest\UrlRule', 'controller' => 'default'],
                ['class' => 'yii\rest\UrlRule', 'controller' => 'v1/default'],
                ['class' => 'yii\rest\UrlRule', 'controller' => 'v2/default'],
                ['class' => 'yii\rest\UrlRule', 'controller' => 'v1/country'],
                //'tokens' => [ '{id}' => 'id:\\\\w+' ]
            ]
        ],
    ],
    'params' => $params,
];

If I comment out the ‘log’ parameter then I get a similar error when initializing the URL parameter. The directories have rwx.

Any ideas or pointers would be much appreciated. Thanks.

log and urlManager should be under the components key.

Thanks! I moved the brackets so that log and URL are in the components section. It progresses a bit further.

I am now getting:

Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: yii\web\UrlRule::0

Can you see any problem with the URL rules?

Thanks. I fixed my routing problem. Firstly, removed the brackets ‘[ ]’ around the rules. Secondly I added the Server name (that I was using in XAMPP) into the rule list and then triggered that controller. I had assumed that the default would have been used but not with enableStrictParsing being set to true.