Hi once I’ve upload my project to ftp strange things happend.
In attachment I’ve uploaded screen which I’ve got once a time. To repair that in my Module.php file in beforeAction i need to add die(); refresh site delete die and website works again. Has anyone problem like that?
Module.php
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\admin\controllers';
public function init()
{
parent::init();
// custom initialization code goes here
}
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
if (\Yii::$app->user->isGuest)
{
\Yii::$app->user->setReturnUrl(\Yii::$app->request->url);
\Yii::$app->session->setFlash('alert', 'Dostęp tylko dla zalogowanych');
\Yii::$app->controller->redirect('/user/login');
}
return true;
} else {
return false;
}
}
}
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\admin\controllers';
public function init()
{
parent::init();
// custom initialization code goes here
}
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
die();
if (\Yii::$app->user->isGuest)
{
\Yii::$app->user->setReturnUrl(\Yii::$app->request->url);
\Yii::$app->session->setFlash('alert', 'Dostęp tylko dla zalogowanych');
\Yii::$app->controller->redirect('/user/login');
}
return true;
} else {
return false;
}
}
}
like that. Since I run it and then remove die, module works fine for some time.
Can you just comment out the entire beforeAction method and report if it works? Your parent::beforeAction is working but not the extended beforeAction method what you have in here.
On initial thoughts… it seems some problem in running your beforeAction method due to possibly some user session problem (the session is generated properly once you run parentAction). You may want to debug your beforeAction method you have in here and how its affecting your session.