我在yii2高级模板上处理小模块,我需要上传图像。上传工作正常,但当我尝试将上传的图片广告在视图中呈现时,我收到此错误:
An Error occurred while handling another error:
exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to perform this action.' in /var/www/html/yii_advance/vendor/yiisoft/yii2/filters/AccessControl.php:15 1
Stack trace:
#0 /var/www/html/yii_advance/vendor/yiisoft/yii2/filters/AccessControl.php(13 4): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
#1 /var/www/html/yii_advance/vendor/yiisoft/yii2/base/ActionFilter.php(71): yii\filters\AccessControl->beforeAction(Object(yii\web\ErrorAction))
#2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
#3 /var/www/html/yii_advance/vendor/yiisoft/yii2/base/Component.php(541): call_user_func(Array, Object(yii\base\ActionEvent))
#4 /var/www/html/yii_advance/vendor/yiisoft/yii2/base/Controller.php(269): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#5 /var/www/html/yii_advance/vendor/yiisoft/yii2/web/Controller.php(108): yii\base\Controller->beforeAction(Object(yii\web\ErrorAction))
#6 /var/www/html/yii_advance/vendor/yiisoft/yii2/base/Controller.php(152): yii\web\Controller->beforeAction(Object(yii\web\ErrorAction))
#7 /var/www/html/yii_advance/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('error', Array)
#8 /var/www/html/yii_advance/vendor/yiisoft/yii2/web/ErrorHandler.php(93): yii\base\Module->runAction('site/error')
#9 /var/www/html/yii_advance/vendor/yiisoft/yii2/base/ErrorHandler.php(109): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#10 [internal function]: yii\base\ErrorHandler- >handleException(Object(yii\web\NotFoundHttpException))
#11 {main}
Previous exception:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "var/www/html/yii_advance/common/upload/slider_image/116.png".' in /var/www/html/yii_advance/vendor/yiisoft/yii2/base/Module.php:460
Stack trace:
#0 /var/www/html/yii_advance/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('var/www/html/yi...', Array)
#1 /var/www/html/yii_advance/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#2 /var/www/html/yii_advance/backend/web/index.php(18): yii\base\Application->run()
#3 {main}
Next exception 'yii\web\NotFoundHttpException' with message 'Page not found.' in /var/www/html/yii_advance/vendor/yiisoft/yii2/web/Application.php:96
Stack trace:
#0 /var/www/html/yii_advance/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 /var/www/html/yii_advance/backend/web/index.php(18): yii\base\Application->run()
#2 {main}
仅对请求图像发生这种情况,页面正确呈现,控制器行为为:
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['access'] = [
'class' => AccessControl::className(),
'rules' =>[
[
'allow' => true,
'roles' => ['@'],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'*' => ['post', 'get']
],
],
];
return $behaviors;
}
图像是我用于创建和更新的表单上的请求: ...
<?php if($model->imageFile):?>
<span><?=$model->imageFile ?></span>
<?= Html::img($model->imageFile) ?>
<?php endif ?>
...
如果我在另一个浏览器标签中打开图像的src我不是同一个问题,权限的文件设置为777以防止错误。 我如何才能看到页面内的图像? 感谢
答案 0 :(得分:0)
您可能没有为错误操作添加规则。 添加以下规则以授予对SiteController上的actionError的访问权限:
'rules'=>[
//...
[
'actions'=>['error'],
'allow'=>true,
],
//...
]