/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model=Loginhistory::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
public function doLogout() { $loginid = Yii::app()->user->login->id; $roleid = Yii::app()->user->role->id; // $count = Loginhistory::model()->update( // Loginhistory::model()->tableName(), // array('logout_time' => date($this->datetimemysqlformatYMDHIS)) // ,'login_id = :loginid AND role_id=:roleid AND logout_time IS NULL' // ,array(':loginid' => $loginid, ':roleid' => $roleid, ) // ); $criteria=new CDbCriteria; $criteria->addCondition('login_id = :loginid AND role_id=:roleid AND logout_time IS NULL'); $criteria->params = array(':loginid' => $loginid, ':roleid' => $roleid, ); $histories = Loginhistory::model()->findAll($criteria); foreach ($histories as $history) { $history->logout_time = date($this->datetimemysqlformatYMDHIS); $history->save(); } Yii::app()->user->logout(); if (!Yii::app()->request->isAjaxRequest) { $this->redirect( Yii::app()->homeUrl ); } else { Yii::app()->end(); } }