{"record":{"id":"f4ee456a40373d4a","repo":"yiisoft/yii2","slug":"the-baseurl-property-must-be-set","errorCode":null,"errorMessage":"The \"baseUrl\" property must be set.","messagePattern":"The \"baseUrl\" property must be set\\.","errorType":"exception","errorClass":"InvalidConfigException","httpStatus":null,"severity":"error","filePath":"framework/base/Theme.php","lineNumber":175,"sourceCode":"            }\n        }\n\n        return $path;\n    }\n\n    /**\n     * Converts a relative URL into an absolute URL using [[baseUrl]].\n     * @param string $url the relative URL to be converted.\n     * @return string the absolute URL\n     * @throws InvalidConfigException if [[baseUrl]] is not set\n     */\n    public function getUrl($url)\n    {\n        if (($baseUrl = $this->getBaseUrl()) !== null) {\n            return $baseUrl . '/' . ltrim($url, '/');\n        }\n\n        throw new InvalidConfigException('The \"baseUrl\" property must be set.');\n    }\n\n    /**\n     * Converts a relative file path into an absolute one using [[basePath]].\n     * @param string $path the relative file path to be converted.\n     * @return string the absolute file path\n     * @throws InvalidConfigException if [[basePath]] is not set\n     */\n    public function getPath($path)\n    {\n        if (($basePath = $this->getBasePath()) !== null) {\n            return $basePath . DIRECTORY_SEPARATOR . ltrim($path, '/\\\\');\n        }\n\n        throw new InvalidConfigException('The \"basePath\" property must be set.');\n    }\n}\n","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/base/Theme.php#L157-L193","documentation":"Thrown by yii\\base\\Theme::getUrl() when the baseUrl property was never set. getUrl() concatenates baseUrl with a relative URL to build absolute theme asset URLs, and unlike some components it has no fallback derivation from basePath, so a null baseUrl is an error. It is a pure configuration guard: the getter returns the raw stored value and the exception fires when it is null.","triggerScenarios":"Calling $view->theme->getUrl('css/main.css') in a layout while the theme was configured with only basePath/pathMap; using Theme::getUrl() in a view helper on a theme instantiated inline with new Theme() and no baseUrl; theme config key misspelled ('baseurl') so the setter never ran.","commonSituations":"A theme set up purely for view-file replacement (pathMap) while some layout still calls $this->theme->getUrl() for asset links; helper code shared across apps where one app's theme lacks baseUrl; config refactor that dropped the baseUrl line unnoticed because view rendering still worked.","solutions":["Add baseUrl to the theme config: 'baseUrl' => '@web/themes/basic'.","Or replace theme->getUrl() calls with direct asset URLs or an AssetBundle, which is the recommended way to publish theme assets in Yii2.","Guard shared helpers: if (Yii::$app->view->theme !== null && Yii::$app->view->theme->getBaseUrl() !== null) before calling getUrl()."],"exampleFix":"// before\n'view' => ['theme' => ['pathMap' => ['@app/views' => '@app/themes/basic/views']]],\necho $view->theme->getUrl('css/main.css'); // baseUrl never set -> throws\n\n// after\n'view' => ['theme' => [\n    'pathMap' => ['@app/views' => '@app/themes/basic/views'],\n    'baseUrl' => '@web/themes/basic',\n]],\necho $view->theme->getUrl('css/main.css');","handlingStrategy":"validation","validationCode":"$theme = Yii::$app->view->theme;\nif ($theme === null || $theme->getBaseUrl() === null) {\n    $url = Yii::getAlias('@web') . '/themes/default/' . ltrim($path, '/'); // fallback URL\n} else {\n    $url = $theme->getUrl($path);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure baseUrl together with any other theme property in one place","Wrap theme->getUrl() calls in a view helper that centralizes the null check","Move theme assets into AssetBundles so URLs come from asset publishing, not theme->getUrl()"],"tags":["php","yii2","theming","assets","urls","configuration"],"backgroundTag":"missing-required-config","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}