我必须在错误处理程序中配置common / main.php文件,但不是重定向错误操作。所以请帮我解决这个错误。
main.php
'components' => [
.......
'errorHandler' => [
'errorAction' => 'site/error',
],
.......
],
SiteController.php
<?php
namespace backend\controllers;
use Yii;
//use yii\web\Controller;
use common\models\LoginForm;
use common\models\EmailTemplate;
use backend\components\BackendController;
use common\models\Users;
//use common\components\Helpers;
/**
* Site controller
*/
class SiteController extends BackendController
{
/**
* @inheritdoc
*/
public function beforeAction($event)
{
//print "before action";exit;
return parent::beforeAction($event);
}
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
public function actionError(){
print "Here: Error Action";exit;
}
public function actionIndex()
{
if(empty(Yii::$app->session['admin_user_id'])){
return $this->redirect(['site/login']);
}
// Yii::$app->Helpers->getSettings('test');
return $this->render('index');
}
}
An Error occurred while handling another error:
exception 'yii\web\NotFoundHttpException' with message 'Your request not found.' in F:\xampp\htdocs\school\backend\components\BackendController.php:52
Stack trace:
#0 F:\xampp\htdocs\school\backend\components\BackendController.php(25): backend\components\BackendController->checkpermission()
#1 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Object.php(107): backend\components\BackendController->init()
#2 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Controller.php(81): yii\base\Object->__construct(Array)
#3 [internal function]: yii\base\Controller->__construct('site', Object(yii\web\Application), Array)
#4 F:\xampp\htdocs\school\vendor\yiisoft\yii2\di\Container.php(366): ReflectionClass->newInstanceArgs(Array)
#5 F:\xampp\htdocs\school\vendor\yiisoft\yii2\di\Container.php(151): yii\di\Container->build('backend\\control...', Array, Array)
#6 F:\xampp\htdocs\school\vendor\yiisoft\yii2\BaseYii.php(340): yii\di\Container->get('backend\\control...', Array)
#7 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Module.php(568): yii\BaseYii::createObject('backend\\control...', Array)
#8 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Module.php(521): yii\base\Module->createControllerByID('site')
#9 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Module.php(449): yii\base\Module->createController('site/error')
#10 F:\xampp\htdocs\school\vendor\yiisoft\yii2\web\ErrorHandler.php(80): yii\base\Module->runAction('site/error')
#11 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\ErrorHandler.php(101): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#12 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#13 {main}
Previous exception:
exception 'yii\web\NotFoundHttpException' with message 'Your request not found.' in F:\xampp\htdocs\school\backend\components\BackendController.php:52
Stack trace:
#0 F:\xampp\htdocs\school\backend\components\BackendController.php(25): backend\components\BackendController->checkpermission()
#1 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Object.php(107): backend\components\BackendController->init()
#2 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Controller.php(81): yii\base\Object->__construct(Array)
#3 [internal function]: yii\base\Controller->__construct('teacher', Object(yii\web\Application), Array)
#4 F:\xampp\htdocs\school\vendor\yiisoft\yii2\di\Container.php(366): ReflectionClass->newInstanceArgs(Array)
#5 F:\xampp\htdocs\school\vendor\yiisoft\yii2\di\Container.php(151): yii\di\Container->build('backend\\control...', Array, Array)
#6 F:\xampp\htdocs\school\vendor\yiisoft\yii2\BaseYii.php(340): yii\di\Container->get('backend\\control...', Array)
#7 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Module.php(568): yii\BaseYii::createObject('backend\\control...', Array)
#8 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Module.php(521): yii\base\Module->createControllerByID('teacher')
#9 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Module.php(449): yii\base\Module->createController('teacher/index')
#10 F:\xampp\htdocs\school\vendor\yiisoft\yii2\web\Application.php(84): yii\base\Module->runAction('teacher/index', Array)
#11 F:\xampp\htdocs\school\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 F:\xampp\htdocs\school\backend\web\index.php(19): yii\base\Application->run()
#13 {main}
发现任何错误或在输出上方显示错误。 请帮帮我
答案 0 :(得分:0)
在你的配置和你的actionError中,没有'问题我使用echo
而不是print
但是是次要问题。
为了查看actionError
我以这种方式评论行动()的工作
public function actions()
{
/*return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];*/
}
否则你总是使用yii\web\ErrorAction
类,而不是你的函数
通过您显示的错误消息我认为问题不是因为您的新错误功能而是与某些许可有关