public function addcategoryAction() { $form = new \Admin\Form\Subject\Category($this->getServiceLocator()); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $data = $form->getData(); /*@var $category \Subject\Model\Subject\Category */ $category = new \Subject\Model\Subject\Category(); $category->exchangeArray($data); $category->setCreatedById($this->user()->getIdentity()); $category->setCreatedDateTime(DateBase::getCurrentDateTime()); $category->setStatus(Subject::STATUS_ACTIVE); $categoryMapper = $this->getServiceLocator()->get('Subject\\Model\\Subject\\CategoryMapper'); $categoryMapper->save($category); if ($form->get('afterSubmit')->getValue()) { return $this->redirect()->toUrl($form->get('afterSubmit')->getValue()); } } } $this->getViewModel()->setVariable('form', $form); return $this->getViewModel(); }
public function editcategoryAction() { /** @var $categoryMapper \Subject\Model\Subject\CategoryMapper */ $categoryMapper = $this->getServiceLocator()->get('Subject\\Model\\Subject\\CategoryMapper'); $category = new Subject\Category(); $id = $this->params()->fromQuery('id'); $category->setId($id); if (!$category->getId() || !$categoryMapper->get($category)) { return $this->page404(); } $form = new \Admin\Form\Subject\Category($this->getServiceLocator()); $form->remove('afterSubmit'); $form->setData($category->toFormValues()); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $category->exchangeArray($form->getData()); $categoryMapper->save($category); return $this->redirect()->toUrl('/admin/subject/category'); } } $this->getViewModel()->setVariables(['form' => $form]); return $this->getViewModel(); }