Пример #1
0
 /**
  * Manage banner creating/updating
  */
 public function formAction()
 {
     if ($this->getParam('id')) {
         $id = $this->model->id = (int) $this->getParam('id');
         $post = $this->model->getByColumn('id', $id);
         if (count($post)) {
             $this->post = $post[0];
             foreach ($this->post as $param => $value) {
                 $this->{$param} = $value;
             }
         } else {
             $link = $this->linkToRoute('admin-slider');
             header("Location: {$link} ");
         }
     }
     if ($this->isPost()) {
         try {
             foreach ($this->getPost() as $postKey => $postValue) {
                 $this->{$postKey} = $postValue;
             }
             $this->model->setTitle($this->getPost('title'));
             $this->model->setUrl($this->getPost('url'));
             $this->model->setStartDate($this->getPost('startdate'));
             $this->model->setEndDate($this->getPost('enddate'));
             $this->result = $this->model->save();
             if (isset($this->result['errors'])) {
                 $this->result['result'] = implode('<br>', $this->result['errors']);
             }
         } catch (\Exception $e) {
             $this->exception = $e;
             $this->throwHttpError(500);
         }
     }
 }