public function actionPercent() { $model = Percent::model()->find(array('order' => 't.percent_date DESC')); if ($_POST['percent']) { $transaction = Yii::app()->db->beginTransaction(); try { $messageType = 'warning'; $message = "There are some errors "; $model = new Percent(); $model->percent_date = date('Y-m-d H:i:s'); $model->percent = $_POST['percent']; if ($model->save()) { $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); $this->redirect(array('site/index')); } } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', "{$e->getMessage()}"); //$this->refresh(); } } $this->render('percent', array('model' => $model)); }
public function getPercent($dates) { $model = Percent::model()->find(array('condition' => 'percent_date <= "' . $dates . '"', 'order' => 't.percent_date DESC')); if (!empty($model)) { return $model->percent; } else { return 0; } }