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); }