Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
1. In the table with users, add the lastActionTime field with the timestamp data type
2. In the model that you save in the action:
protected function afterSave() {
if (parent::afterSave()) {
$user = User::model()->findByPk(Yii::app()->user->id);
$user->lastActionTime = date('Y-m-d H:i:s');
$user->save();
return true;
} else return false;
}
public function filters() {
return array(
'LastActionTime + index'
);
}
public function filterLastActionTime($filterChain) {
$user = User::model()->findByPk(Yii::app()->user->id);
if ($user->lastActionTime > date('Y-m-d H:i:s', time() - 60 * 30)) { // 30 минут
Yii::app()->user->setFlash('error', 'Вы уже выполняли это действие меньше чем полчаса назад :(');
$this->redirect(Yii::app()->homeUrl);
}
$filterChain->run();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question