gpt4 book ai didi

yii - Yii 2 中的应用程序文件重组

转载 作者:行者123 更新时间:2023-12-04 08:31:23 27 4
gpt4 key购买 nike

我已经建立了新的 Yii2 项目。现在我想 reorganize folder structure在“public”和“app”两个文件夹中(实际上代表 protected 文件)。

框架中的所有代码都放在“app”文件夹中。在“公共(public)”文件夹中,我只有一个名为“index.php”的脚本,我从那里调用应用程序。那里的代码如下所示(我只修改了原始“index.php”的路径)。

app/index.php

<?php

// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../app/vendor/autoload.php');
require(__DIR__ . '/../app/vendor/yiisoft/yii2/Yii.php');

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

(new yii\web\Application($config))->run();

?>

同样的方法在 Yii 框架中工作,我们得到了不同的命令语法。但是现在在 Yii 2 中我遇到了以下问题:

enter image description here

所以似乎所有路径都指向正确的文件(我已经检查过),但我仍然遇到错误。那么我在这里缺少什么?为什么 basePath 仍然识别“公共(public)”文件夹?

更新 1:

按照@marche 的评论,将以下代码添加到配置文件中:

'components' => [
...
'assetManager' => [
'basePath' => 'my/path/to/assets',
],
...
],

我不再收到屏幕错误,但现在加载的内容没有任何 CSS 样式和 JS 文件(他们仍然从错误的地方提取 URL)。

最佳答案

如果您想更改 Assets 目录,您需要在配置文件 web.php 上配置 AssetsManager 组件:

'components' => [
...
'assetManager' => [
'basePath' => 'my/path/to/assets',
],
...
],

关于yii - Yii 2 中的应用程序文件重组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33158976/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com