简体   繁体   English

标签“ Yii”已定义

[英]Label 'Yii' already defined

I am starting to learn Yii framework. 我开始学习Yii框架。 In the tutorial video i copied the code where were using setFlash for error messages on a form. 在教程视频中,我将代码复制到了使用setFlash在表单上显示错误消息的位置。 I have inspected the code a lot of times and im pretty sure its identical to the video however i keep getting an error message that is referring to this line: 我已经检查了很多次代码,并且非常确定它与视频相同,但是我不断收到一条错误消息,该错误消息指向此行:

Yii:app()->user->setFlash('failure', "There was a problem saving the data!");

The error says: 错误提示:

Fatal error: Label 'Yii' already defined in C:\wamp\www\photogallery\protected\controllers\AlbumController.php on line 77

public function actionCreate()
{
    $model=new Album;

    // Uncomment the following line if AJAX validation is needed
    $this->performAjaxValidation($model);

    if(isset($_POST['Album']))
    {
        $model->attributes=$_POST['Album'];
        if($model->save()){
            Yii:app()->user->setFlash('saved', "Data saved!");
            $this->redirect(array('update','id'=>$model->id));
        } else{
            Yii:app()->user->setFlash('failure', "There was a problem saving the data!");
        }

    }

    $this->render('create',array(
        'model'=>$model,
    ));
}

Maybe its a typo im missing but its exactly the same as the video tutorial and it seems to work for him and i took a look at some other similar code online and it seemed to use 2 instances of Yii:app() in an if/else statement. 也许它没有错字,但与视频教程完全一样,并且似乎对他有用,我在网上看了一些其他类似的代码,它似乎在if /中使用2个Yii:app()实例其他声明。 The error message didnt return any similar issues on google so im guessing its something simple 错误消息没有在Google上返回任何类似的问题,所以我猜它很简单

You need to use a double colon, not single, when using the static method. 使用静态方法时,需要使用双冒号而不是单冒号。

Yii::app() not Yii:app() Yii::app()不是Yii:app()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM