Php Yii2罐';在使用公共目录运行多个应用程序时找不到文件
我正在运行Php Yii2罐';在使用公共目录运行多个应用程序时找不到文件,php,yii,yii2,Php,Yii,Yii2,我正在运行Yii2,直到最近我还在一个应用程序中工作;然而,我需要开始添加一个管理区域,我没有开始使用高级应用程序模板,只是基本的模板,但仍然移动了一些目录,一切都很好 现在我有一个这样的目录结构 admin/ system/ controllers/ models/ views/ index.php common/ vendor/ .bowerrc composer.json composer.lo
Yii2
,直到最近我还在一个应用程序中工作;然而,我需要开始添加一个管理区域,我没有开始使用高级应用程序模板,只是基本的模板,但仍然移动了一些目录,一切都很好
现在我有一个这样的目录结构
admin/
system/
controllers/
models/
views/
index.php
common/
vendor/
.bowerrc
composer.json
composer.lock
yii
yii.bat
console/
css/
images/
js/
system/
controllers/
models/
views/
index.php
如您所见,根目录
目录充当web
目录,系统
目录充当前端
的应用程序
目录
网站的前端工作非常好,但是我在管理部分遇到了问题
在admin
dir中,base
dir充当web
目录admin/system/
充当应用程序
目录
这是我在尝试访问时遇到的错误:admin/staff/login
无效参数–yii\base\InvalidParamException
要发布的文件或目录不存在:common\vendor\bower/jquery/dist
这是admin/index.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__ . '/../common/vendor/autoload.php');
require(__DIR__ . '/../common/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../common/config/bootstrap.php');
require(__DIR__ . '/../common/config/constants.php');
$config = require(__DIR__ . '/system/config/main.php');
(new yii\web\Application($config))->run();
<?php
$params = require(__DIR__ . '/../../../common/config/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'version' => '0.1',
'vendorPath' => 'common\vendor',
'defaultRoute' => 'site/index',
'bootstrap' => [
'log',
'common\base\Settings',
],
'components' => [
'request' => [
'enableCookieValidation' => false,
'enableCsrfCookie' => false,
'csrfParam' => '_admin_csrf',
],
'view' => [
'theme' => [
// This data is setup dynamically via the bootstrapping process
],
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\Staff',
'enableAutoLogin' => false,
'loginUrl' => 'staff/login',
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'session' => [
'name' => 'PHPADMINSESSID',
],
'formatter' => [
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
// The below viewPath only acts as the base dir and will be changed during the bootstrap process to append the correct locale dir to it
'viewPath' => '@common/mail',
// These are relative to the final value of viewPath
'htmlLayout' => 'layouts/default-html',
'textLayout' => 'layouts/default-text',
],
'authManager' => [
'class' => 'app\components\AuthManager',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error'],
'logFile' => '@app/runtime/logs/errors.log',
],
[
'class' => 'yii\log\FileTarget',
'levels' => ['warning'],
'logFile' => '@app/runtime/logs/warnings.log',
],
[
'class' => 'yii\log\FileTarget',
'levels' => ['info'],
'logFile' => '@app/runtime/logs/info.log',
'enabled' => false,
],
[
'class' => 'yii\log\FileTarget',
'levels' => ['trace'],
'logFile' => '@app/runtime/logs/trace.log',
'enabled' => false,
],
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
],
],
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapPluginAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
],
],
],
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/languages',
//'on missingTranslation' => ['common\components\TranslationEventHandler', 'handleMissingTranslation'],
],
],
],
'db' => require(__DIR__ . '/../../../common/config/db.php'),
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'allowedIPs' => ['127.0.0.1','::1']
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1','::1']
];
}
return $config;
以下是admin/system/config/main.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__ . '/../common/vendor/autoload.php');
require(__DIR__ . '/../common/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../common/config/bootstrap.php');
require(__DIR__ . '/../common/config/constants.php');
$config = require(__DIR__ . '/system/config/main.php');
(new yii\web\Application($config))->run();
<?php
$params = require(__DIR__ . '/../../../common/config/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'version' => '0.1',
'vendorPath' => 'common\vendor',
'defaultRoute' => 'site/index',
'bootstrap' => [
'log',
'common\base\Settings',
],
'components' => [
'request' => [
'enableCookieValidation' => false,
'enableCsrfCookie' => false,
'csrfParam' => '_admin_csrf',
],
'view' => [
'theme' => [
// This data is setup dynamically via the bootstrapping process
],
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\Staff',
'enableAutoLogin' => false,
'loginUrl' => 'staff/login',
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'session' => [
'name' => 'PHPADMINSESSID',
],
'formatter' => [
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
// The below viewPath only acts as the base dir and will be changed during the bootstrap process to append the correct locale dir to it
'viewPath' => '@common/mail',
// These are relative to the final value of viewPath
'htmlLayout' => 'layouts/default-html',
'textLayout' => 'layouts/default-text',
],
'authManager' => [
'class' => 'app\components\AuthManager',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error'],
'logFile' => '@app/runtime/logs/errors.log',
],
[
'class' => 'yii\log\FileTarget',
'levels' => ['warning'],
'logFile' => '@app/runtime/logs/warnings.log',
],
[
'class' => 'yii\log\FileTarget',
'levels' => ['info'],
'logFile' => '@app/runtime/logs/info.log',
'enabled' => false,
],
[
'class' => 'yii\log\FileTarget',
'levels' => ['trace'],
'logFile' => '@app/runtime/logs/trace.log',
'enabled' => false,
],
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
],
],
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapPluginAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
],
],
],
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/languages',
//'on missingTranslation' => ['common\components\TranslationEventHandler', 'handleMissingTranslation'],
],
],
],
'db' => require(__DIR__ . '/../../../common/config/db.php'),
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'allowedIPs' => ['127.0.0.1','::1']
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1','::1']
];
}
return $config;
我认为路径可能是
require(__DIR__ . '/../../common/vendor/autoload.php');
require(__DIR__ . /..'/../common/vendor/yiisoft/yii2/Yii.php');
....
这可能会为在其他组件内部调用的组件或未设置特定路径(例如jquery)的组件带来问题。我相信原因可能是这样的,然后为了解决这个问题,您将目录供应商恢复为其默认配置,或者标识必须使用适当路径加载的组件。问题是管理配置文件中的这一行:
'vendorPath' => 'common\vendor',
common
不作为别名,我需要将其更改为:
'vendorPath' => '..\common\vendor',
…以正确引用公共
目录。我会尝试一下,但为什么会这样?\uuuu DIR\uuuuu
没有得到你当前的DIR吗,那就是admin/
,所以你只需要一个/../
?没有,没有用。抱怨在我做了这些更改后找不到这些文件。我已经更新了答案,希望这个建议对你有用。