Yii:app()->user->name ----- Why is it not working?

时间:2015-07-28 16:07:02

标签: php yii

I have written it in layouts/main.php but whenever I am trying to run the application following error has been occured

Undefined property: CWebApplication::$user in ........ main.php on line...

And how its work can anyone please explain.

public static function model($className=__CLASS__)
{
    return parent::model($className);
}

2 个答案:

答案 0 :(得分:0)

尝试使用::代替:

   Yii::app()->user->name;

答案 1 :(得分:0)

如果要访问类的静态方法,请使用

classname::methodname();

所以,要访问类Yii {}

的静态app()方法
class YiiBase {
  public static function app() {
    return self::$_app;
  }
}
class Yii extends YiiBase {
}
Yii::app(); //You, need to do this

hope, this might help