{"record":{"id":"5334226f0f08ec6c","repo":"yiisoft/yii2","slug":"the-id-configuration-for-the-application-is-requ","errorCode":null,"errorMessage":"The \"id\" configuration for the Application is required.","messagePattern":"The \"id\" configuration for the Application is required\\.","errorType":"exception","errorClass":"InvalidConfigException","httpStatus":null,"severity":"error","filePath":"framework/base/Application.php","lineNumber":218,"sourceCode":"        $this->preInit($config);\n\n        $this->registerErrorHandler($config);\n\n        Component::__construct($config);\n    }\n\n    /**\n     * Pre-initializes the application.\n     * This method is called at the beginning of the application constructor.\n     * It initializes several important application properties.\n     * If you override this method, please make sure you call the parent implementation.\n     * @param array $config the application configuration\n     * @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing.\n     */\n    public function preInit(&$config)\n    {\n        if (!isset($config['id'])) {\n            throw new InvalidConfigException('The \"id\" configuration for the Application is required.');\n        }\n        if (isset($config['basePath'])) {\n            $this->setBasePath($config['basePath']);\n            unset($config['basePath']);\n        } else {\n            throw new InvalidConfigException('The \"basePath\" configuration for the Application is required.');\n        }\n\n        if (isset($config['vendorPath'])) {\n            $this->setVendorPath($config['vendorPath']);\n            unset($config['vendorPath']);\n        } else {\n            // set \"@vendor\"\n            $this->getVendorPath();\n        }\n        if (isset($config['runtimePath'])) {\n            $this->setRuntimePath($config['runtimePath']);\n            unset($config['runtimePath']);","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/base/Application.php#L200-L236","documentation":"yii\\base\\Application::preInit() runs at the very start of the constructor and enforces two mandatory config keys, checked in order: 'id' then 'basePath'. A missing 'id' throws InvalidConfigException immediately - every Yii application requires a unique id, used to distinguish assets, caches, and sessions when several apps run side by side.","triggerScenarios":"new \\yii\\web\\Application($config) or the console Application with a config array lacking 'id'; booting a minimal application for a microservice or test bootstrap; an entry script that includes an empty or wrong config file (the include returned an empty array).","commonSituations":"Test harnesses constructing the application from a slimmed config; splitting config into web.php/console.php and forgetting 'id' in one variant; a config file that conditionally returns early so keys are dropped.","solutions":["Add 'id' => 'myapp' to the config array passed to the Application constructor","Verify which config file the entry script includes - the throw proves the loaded array really lacks the key","Use distinct ids per entry point (app-frontend, app-console) in multi-app setups"],"exampleFix":"// before\nnew \\yii\\console\\Application(['basePath' => __DIR__, 'components' => []]);\n\n// after\nnew \\yii\\console\\Application(['id' => 'console', 'basePath' => __DIR__, 'components' => []]);","handlingStrategy":"validation","validationCode":"foreach (['id', 'basePath'] as $key) {\n    if (!isset($config[$key])) {\n        throw new \\InvalidArgumentException(\"App config is missing '{$key}'\");\n    }\n}\n$app = new \\yii\\console\\Application($config);","typeGuard":null,"tryCatchPattern":"try {\n    $app = new \\yii\\web\\Application($config);\n} catch (\\yii\\base\\InvalidConfigException $e) {\n    error_log('App config incomplete, loaded file: ' . $configFile);\n    throw $e;\n}","preventionTips":["Keep one canonical config builder that always injects id and basePath","Add a boot smoke test that constructs the application for every entry script","Never let config files conditionally return early; always return the full array"],"tags":["configuration","application","bootstrap"],"backgroundTag":"missing-required-config-key","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}