I’m having issues redirecting users from my component to Login page view. Below is the code with all the solutions I tried…My view file is located in frontend/view/site/login.php
<?php
namespace frontend\components;
use Yii;
use yii\base\Behavior;
class VerifyLog extends Behavior
{
public function events()
{
return [
\yii\web\Application::EVENT_BEFORE_REQUEST => 'VerifyLog',
];
}
public function VerifyLog()
{
if(Yii::$app->user->isGuest)
{
//None of these are working
// return $this->render('login');
// return $this->goHome();
//return Yii::$app->view->render('site/login');
// return Yii::$app->view->render('@app/views/site/login.php');
//return $this->redirect(['view']);
}
}
}
?>
Also on that note(newbie question) is there any difference btn
1. if(!\Yii::$app->user->isGuest)
2. if(Yii::$app->user->isGuest)
3. if(\Yii::$app->user->isGuest)