Ejemplo n.º 1
0
 public function addAction()
 {
     $formCategory = new CategoryForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $category = new Category();
         $formCategory->setInputFilter($category->getInputFilter());
         $formCategory->setData($request->getPost());
         if ($formCategory->isValid()) {
             $category->exchangeArray($formCategory->getData());
             $this->categoryTable->saveCategory($category);
             return $this->redirect()->toRoute('home');
         }
     }
     return new ViewModel(array('form' => $formCategory));
 }
Ejemplo n.º 2
0
 public function editAction()
 {
     $request = $this->getRequest();
     $formCategory = new CategoryForm();
     $formCategory->get('submit')->setValue('Modifier');
     $idCategory = $this->params()->fromRoute('id', null);
     if ($request->isPost()) {
         $category = $this->getServiceLocator()->get('Jobeet/Model/Category');
         $formCategory->setData($request->getPost());
         $category->id_category = $idCategory;
         $formCategory->setInputFilter($category->getInputFilter());
         $formCategory->getInputFilter()->get('name')->getValidatorChain()->attachByName('Db\\NoRecordExists', array('adapter' => $category->getDbAdapter(), 'table' => 'category', 'field' => 'name', 'exclude' => array('field' => 'id_category', 'value' => $category->id_category)));
         $formCategory->getInputFilter()->get('slug')->getValidatorChain()->attachByName('Db\\NoRecordExists', array('adapter' => $category->getDbAdapter(), 'table' => 'category', 'field' => 'slug', 'exclude' => array('field' => 'id_category', 'value' => $category->id_category)));
         if ($formCategory->isValid()) {
             $category->exchangeArray($formCategory->getData());
             $this->categoryTable->saveCategory($category);
             $this->flashMessenger()->addMessage(array('success' => "Category '{$category->name}' was updated successfully"));
             return $this->redirect()->toRoute('zfcadmin/category');
         }
     }
     $category = $this->categoryTable->getCategoryById($idCategory);
     $formCategory->setData($category->getArrayCopy());
     return new ViewModel(array('form' => $formCategory));
 }