I am trying to check is the user logged inside my view file, but I keep getting this error:
Call to undefined method Yii::app()
I tried adding $ before app but the error is still there (this time it is Undefined variable: app). Is it possible to this is view?
This is the code I use the check if the user is logged:
<?php
if(Yii::app()->isGuest)
echo 'User is not logged!';
?>
In yii2 you have to define the
app()
with$
sign as$app()
.In Yii2 the correct syntax is
or
Look at the documentation for more details: http://www.yiiframework.com/doc-2.0/yii-web-user.html
Hope it helps.