2

我正在尝试从 YII2 开始(我应该说在 ASP.NET MVC 之后相当困难)并且得到了这个错误,但无法得到什么是错误的 - id 属性已设置。

<?php
return [
    'id' => 'crmapp',
    'basePath' => realpath(__DIR__ . '/../'),
    'components' => [
        'request' => [
            'cookieValidationKey' => 'somekey'
        ],
        'urlManager'=>[
            'enablePrettyUrl'=>true,
            'showScriptName'=>false
        ]
    ],
    'db'=> [
        require(__DIR__.'/db.php'),
    ]];

这是完整的错误文本:

Fatal error: Uncaught exception 'yii\base\InvalidConfigException' with message 'The "id" configuration for the Application is required.' in C:\xampp\htdocs\crmapp\vendor\yiisoft\yii2\base\Application.php:220 Stack trace: #0 C:\xampp\htdocs\crmapp\vendor\yiisoft\yii2\base\Application.php(202): yii\base\Application->preInit('C:\\xampp\\htdocs...') #1 C:\xampp\htdocs\crmapp\web\index.php(10): yii\base\Application->__construct('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\crmapp\vendor\yiisoft\yii2\base\Application.php on line 220

这是 web/index.php

<?php
require(__DIR__.'/../vendor/yiisoft/yii2/Yii.php');
$config = (__DIR__.'/../config/web.php');
(new yii\web\Application($config))->run();
4

1 回答 1

4

这是你的问题:

$config = (__DIR__.'/../config/web.php');

$config包含 的路径web.php,而不是其内容。它应该是:

$config = require(__DIR__ . '/../config/web.php');
于 2015-11-05T11:58:22.613 回答