Example #1
0
 /**
  * Edit action method
  *
  * @param  int $id
  * @return void
  */
 public function edit($id)
 {
     $view = new Model\View();
     $view->getById($id);
     $fields = $this->application->config()['forms']['Phire\\Views\\Form\\View'];
     $this->prepareView('views/edit.phtml');
     $this->view->title = 'Views';
     $this->view->view_name = $view->name;
     $fields[1]['name']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);';
     if ($this->application->isRegistered('phire-fields')) {
         $models = $this->application->module('phire-fields')->config()['models'];
         foreach ($models as $model => $type) {
             $fields[2]['model_1']['value'][$model] = $model;
         }
     }
     $viewAry = $view->toArray();
     $viewAry['group_fields'] = $viewAry['_group_fields'];
     $viewAry['single_fields'] = $viewAry['_single_fields'];
     $this->view->form = new Form\View($fields);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($viewAry);
     if ($this->request->isPost()) {
         $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $view = new Model\View();
             $view->update($this->view->form->getFields());
             $this->view->id = $view->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/views/edit/' . $view->id);
         }
     }
     $this->send();
 }