public function addeditAction() { // action body $oCategoryForm = new Application_Form_Category(); $this->view->categoryform = $oCategoryForm; if ($this->getRequest()->isPost()) { if ($oCategoryForm->isValid($this->getRequest()->getPost())) { $saFormDetails = $oCategoryForm->getValues(); $oCategoryExist = Doctrine::getTable('Model_Category')->checkCategoryExist($saFormDetails['id_users']); if (count($oCategoryExist) > 0 && $this->getRequest()->getParam('id_category') == "") { $this->view->errorMessage = "This category is already exist."; } elseif ($this->getRequest()->getParam('id_category') != "" && isset($oCategoryExist[0]) && $oCategoryExist[0]['id_category'] != $this->getRequest()->getParam('id_category')) { $this->view->errorMessage = "This category is already exist."; } else { $oCategory = new Model_Category(); $snIdUser = $oCategory->saveAndUpdateCategoryDetails($oCategory, $saFormDetails, $this->getRequest()->getParam('id_category') != 0 ? $this->getRequest()->getParam('id_category') : ''); $this->_redirect('/admin/category/list'); } } } elseif ($this->getRequest()->getParam('id') != '') { $oCategory = Doctrine::getTable('Model_Category')->getCategoryDetailById($this->getRequest()->getParam('id')); $oCategoryForm->populate($oCategory[0]); } $this->view->param = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : ''; }
public function updateAction() { $form = new Application_Form_Category(); $category_model = new Application_Model_Category(); $id = $this->getRequest()->getParam('id'); $values = $category_model->getCategoryById($id)->toArray(); $this->view->form = $form->populate($values[0]); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getParams())) { $this->view->submit = 'done'; $name = $form->getValues(); var_dump($name); $category_model = new Application_Model_Category(); $category_model->updateCategory($id, $name); } } $this->render('form'); }
public function editAction() { $id = $this->_request->getParam("id"); $form = new Application_Form_Category(); $form->getElement("picture")->setRequired(false); if ($this->_request->isPost()) { if ($form->isValid($this->_request->getParams())) { $info = $form->getValues(); $category_model = new Application_Model_Category(); $category_model->editCategory($info); $this->redirect("category/list"); } } if (!empty($id)) { $category_model = new Application_Model_Category(); $cat = $category_model->getCategoryById($id); $form->populate($cat[0]); } $this->view->form = $form; $this->render('add'); }