public function modifyAction() { $id = (int) $this->params()->fromRoute('id'); if (!$id) { return $this->redirect()->toRoute('page', ['action' => 'add']); } $page = $this->getPageTable()->getPage($id); $form = new PageForm(); $form->bind($page); //Связь формы и страницы $form->get('submit')->getAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($page->getInputFilter()); //Привязываем фильтр //Заполняем форму значениями $form->setData($request->getPost()); if ($form->isValid()) { $this->getPageTable()->savePage($page); //Возвращаем и сохраняем return $this->redirect()->toRoute('page'); } } return ['id' => $id, 'form' => $form]; }
public function editAction($id) { $id = (int) $id; $form = new PageForm(); $model = Page::findFirst($id); if ($model->getSlug() == 'index') { $form->get('slug')->setAttribute('disabled', 'disabled'); } if ($this->request->isPost()) { $post = $this->request->getPost(); $form->bind($post, $model); if ($form->isValid()) { $model->updateFields($post); if ($model->save()) { $this->flash->success($this->helper->at('Updated has been successful')); // Очищаем кеш страницы $query = "slug = '{$model->getSlug()}'"; $key = md5("Page::findFirst({$query})"); $this->cache->delete($key); return $this->redirect($this->url->get() . 'page/admin/edit/' . $model->getId() . '?lang=' . LANG); } else { $this->flashErrors($model); } } else { $this->flashErrors($form); } } else { $form->setEntity($model); } $this->view->model = $model; $this->view->form = $form; $this->helper->title($this->helper->at('Edit Page'), true); }
public function editAction($id) { $id = (int) $id; $form = new PageForm(); $model = Page::findFirst(array("id = {$id}")); if ($this->request->isPost()) { $form->bind($this->request->getPost(), $model); if ($form->isValid()) { if ($model->save()) { $this->flash->success('Информация обновлена'); // Очищаем кеш страницы $query = "slug = '{$model->getSlug()}'"; $key = md5("Page::findFirst({$query})"); $this->cache->delete($key); return $this->redirect('/page/admin/edit/' . $model->getId()); } else { $this->flashErrors($model); } } else { $this->flashErrors($form); } } else { $form->setEntity($model); } $this->view->model = $model; $this->view->form = $form; $this->view->title = 'Редактирование страницы'; $this->helper->title('Редактирование страницы'); }
/** * * @return type */ public function editAction() { $id = (int) $this->params()->fromRoute("id"); // Debug::dump($id); if ($id == NULL) { $this->redirect()->toRoute("page/actions", array("action" => "add")); } $page = $this->getPageTable()->getPage($id); $form = new PageForm(); // $form->setData($page->toArray()); $form->bind($page); $form->get("submit")->setAttribute("value", "Редактировать"); if ($this->request->isPost()) { $form->setInputFilter($page->getInputFilter()); $form->setData($this->request->getPost()); if ($form->isValid()) { //возвращает Page, т.к. выше bind $page->exchangeArray($form->getData()->getArrayCopy()); $this->getPageTable()->savePage($page); $this->redirect()->toRoute("page"); } } return array("form" => $form, "id" => $id); }