Hello World!
я создал в пользовательской таблице last_activity, чтобы проверить, когда пользователь вошел в систему, как изменить значение на 0000-00-00 00:00:00 после выхода пользователя из системы.
public function actionLogout()
{
$event = $this->getUserEvent(\Yii::$app->user->identity);
/* $account = $this->finder->findAccount()->byClient($client)->one();
$account->user->updateAttributes(['last_activity' => '0000-00-00 00:00:00']);*/
$this->trigger(self::EVENT_BEFORE_LOGOUT, $event);
$logout = \Yii::$app->getUser()->logout();
/* if ($logout){
$module = \Yii::$app->getModule('user');
$module->updateAttributes(['last_activity'=>'0000-00-00 00:00:00']);
}*/
$this->trigger(self::EVENT_AFTER_LOGOUT, $event);
// \Yii::$app->user->updateAttributes(['last_activity' => 0]);
// User::deleteLast();
// \Yii::$app->user->updateAttributes(['last_activity' => '0000-00-00 00:00:00']);
// $this->updateAttributes(['last_activity' => '0000-00-00 00:00:00']);
// $this->user->updateAttributes(['last_activity' => null]);
// return Yii::$app->user->updateAttributes(['last_ip'=> 1]);
return $this->redirect(site/index);
}
Просмотреть файл Cabinet-panel.php
<?php
echo Menu::widget([
'items' => [
////
[
'label' => Yii::t('main', "Logout"),
'url' => null,
'options' => ['class' => 'li-logout'],
'template' => '<a id="link-logout">{label}</a>'
],
],
'options' => [
'class' => 'nav nav-pills nav-stacked'
],
'activeCssClass' => 'active',
'route' => Yii::$app->request->url,
'activateItems' => true,
]);
?>
common.js вот функция, которая срабатывает, когда пользователь нажимает на тег привязки
function logout() {
$(document).on('click', '#link-logout', function () {
$.post(getLang() + '/user/security/logout/');
});
}
logout();