doubi8383 2016-03-18 00:17
浏览 231
已采纳

Yii2声明beforeAction应与Controller兼容

Whenever I include the beforeAction function event with something simple I get an error saying it has to be compatible. This does not happen on my live server only on my local one. The only difference I can think of is my local server is running PHP7 and my live one is running PHP5.6. Is that what is causing the issue? The only thing I have found that will fix it is removing it completely.

This is what my beforeAction looks like

 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;
            }
        }
    }

I also tried this simple one to check and got the same issue

public function beforeAction()
    {
        if (!parent::beforeAction($action)) {
            return false;
        }
        return true;
    }

Here is the error message I get

Declaration of frontend\controllers\EventController::beforeAction() should be compatible with yii\web\Controller::beforeAction($action)
  • 写回答

2条回答 默认 最新

  • dozr13344 2016-03-18 03:33
    关注

    See this error message :

    should be compatible with yii\web\Controller::beforeAction($action)
    

    Your override function must be compatible with parent. So, valid code :

    public function beforeAction($action)
        { 
            ....
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 计算二重积分∫∫e^(x+y)dxdy,其中0≤x≤1,0≤y≤1,试分别用复合辛普森公式(取n=4)以及高斯求积公式(取n=4)计算积分 给出matlab程序
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的