示例#1
0
 /**
  * Edit action method
  *
  * @param  int $id
  * @return void
  */
 public function edit($id)
 {
     $tag = new Model\Tag();
     $tag->getById($id);
     if (!isset($tag->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/tags');
     }
     $this->prepareView('tags/edit.phtml');
     $this->view->title = 'Tags';
     $this->view->tag_title = $tag->title;
     $fields = $this->application->config()['forms']['Phire\\Tags\\Form\\Tag'];
     $fields[1]['title']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);';
     $this->view->form = new Form\Tag($fields);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($tag->toArray());
     if ($this->request->isPost()) {
         $this->view->form->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $tag = new Model\Tag();
             $tag->update($this->view->form->getFields());
             $this->view->id = $tag->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/tags/edit/' . $tag->id);
         }
     }
     $this->send();
 }