I am working on a PHP Yii2 application. I have a strange problem with yii2, here is my problem.
As we know, there is a web \ assets folder in the Yii2 project, and it will load its own asset package, but when setting up the load balance, I found that the Chrome Chrome tool console gives some errors below:
http://firekylin.eastasia.cloudapp.azure.com/assets/fde0fce1/css/bootstrap.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://firekylin.eastasia.cloudapp.azure.com/assets/ebd0699a/css/AdminLTE.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://firekylin.eastasia.cloudapp.azure.com/assets/5e97633a/jquery.js Failed to load resource: the server responded with a status of 404 (Not Found)
yii.js:464 Uncaught ReferenceError: jQuery is not defined(β¦)
http://firekylin.eastasia.cloudapp.azure.com/assets/14e563af/yii.validation.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://firekylin.eastasia.cloudapp.azure.com/assets/fde0fce1/js/bootstrap.js Failed to load resource: the server responded with a status of 404 (Not Found)
yii.activeForm.js:14 Uncaught TypeError: Cannot read property 'fn' of undefined(β¦)
http://firekylin.eastasia.cloudapp.azure.com/assets/fde0fce1/js/bootstrap.js Failed to load resource: the server responded with a status of 404 (Not Found)
app.min.js:13 Uncaught Error: AdminLTE requires jQuery(β¦)
index.php:555 Uncaught ReferenceError: jQuery is not defined(β¦)
http://firekylin.eastasia.cloudapp.azure.com/assets/88d3a068/css/font-awesome.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://firekylin.eastasia.cloudapp.azure.com/assets/ebd0699a/css/skins/_all-skins.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
It canβt find the js, css file when using the ip load balance for visiting, but as soon as I use the ip server, where the Yii2 application exactly works, the web page will successfully load the js, css file:
left uses the load load server to visit, and right uses the Yii2 server to visit
There are two servers that precisely control Yii2, and both of them have their own web \ assets folder and have different caches:
web \ assets folders on two Yii2 servers
, Yii2, . , , - Yii2. , Yii2 md5 , , , "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\,
:
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'defaultRoute'=>'firekylin',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'view' => [
'theme' => [
'pathMap' => [
'@app/views' => '@app/views/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app'
],
],
],
'assetManager' => [
'class' => 'yii\web\AssetManager',
'forceCopy' => true,
],
'request' => [
'cookieValidationKey' => '2MhlyGaaGs_uqt_apwy1jLahR_wZ8dBv',
'parsers' => [
'application/json' => 'yii\web\JsonParser',
'text/json' => 'yii\web\JsonParser',
]
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\OriginUser',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
],
'params' => $params,
];
if (YII_ENV_DEV) {
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
$config['components']['assetManager']['forceCopy'] = true;
}
return $config;
public function beforeAction($action){
Yii::$app->assetManager->forceCopy = YII_DEBUG;
return parent::beforeAction($action);
}
assetManager
$config['components']['assetManager']['forceCopy'] = true;
config\web.php beforeAction , , . ?