Hello World!
i created in the user table a last_activity to check when the user logged in, how to change the value to 0000-00-00 00:00:00 after a user logout.
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);
}
View 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
here is the function, that works when a user clicks on the anchor tag
function logout() {
$(document).on('click', '#link-logout', function () {
$.post(getLang() + '/user/security/logout/');
});
}
logout();