【发布时间】:2016-03-18 00:17:33
【问题描述】:
每当我将beforeAction 函数事件包含在一些简单的东西中时,我都会收到一条错误消息,指出它必须兼容。这不会仅在我的本地服务器上发生在我的实时服务器上。我能想到的唯一区别是我的本地服务器运行的是 PHP7,而我的实时服务器运行的是 PHP5.6。这是造成问题的原因吗?我发现唯一能修复它的就是完全删除它。
这就是我的beforeAction 的样子
public function beforeAction()
{
if(Yii::$app->user->isGuest){
return $this->redirect(['site/login']);
} else {
if(strtotime(UserInfo::findOne(Yii::$app->user->Id)->active_until) < strtotime(date("Y-m-d H:i:s"))){
Yii::$app->session->setFlash('warning', 'You need an active subscription to access events.');
echo("<script>location.href = '".Url::toRoute('site/subscription')."';</script>");
exit;
//return $this->redirect(['site/subscription']);
}else {
return true;
}
}
}
我也试过这个简单的检查并遇到同样的问题
public function beforeAction()
{
if (!parent::beforeAction($action)) {
return false;
}
return true;
}
这是我收到的错误消息
Declaration of frontend\controllers\EventController::beforeAction() should be compatible with yii\web\Controller::beforeAction($action)
【问题讨论】:
-
试过这个吗?返回父级::beforeAction($action);
-
是的,我也试过了
-
希望这会有所帮助.. 没主意了哈哈。 stackoverflow.com/questions/4017193/…
-
刚刚尝试过,仍然出现该错误