Beispiel #1
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     if (!empty($this->id)) {
         $model = Ad::findOne($this->id);
     }
     if (!isset($model) || empty($model)) {
         $model = new Ad();
     }
     $model->setAttributes(['name' => $this->name, 'position' => $this->position, 'code' => $this->code, 'state' => $this->state, 'enableDate' => strtotime($this->enableDate), 'disableDate' => strtotime($this->disableDate)]);
     if ($model->save(false)) {
         $this->id = $model->id;
     }
     return !empty($this->id);
 }
Beispiel #2
0
 public function actionEdit($id)
 {
     $ad = Ad::findOne($id);
     if (!$ad) {
         throw new NotFoundHttpException("Не найден баннер с идентификатором {$id}!");
     }
     $model = new BannerForm();
     $model->loadAd($ad);
     if (\Yii::$app->request->post("BannerForm") && $model->load(\Yii::$app->request->post())) {
         if ($model->save()) {
             \Yii::$app->session->setFlash('success', 'Баннер успешно отредактирован!');
         } else {
             \Yii::$app->session->setFlash('error', 'Произошла ошибка при сохранении баннера');
         }
     }
     return $this->render('edit', ['model' => $model]);
 }
Beispiel #3
0
 /**
  * Finds the Ad model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Ad the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Ad::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }