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 createAction()
 {
     $frmCate = new Application_Form_Category();
     if ($this->getRequest()->isPost()) {
         $cateName = $this->_request->getParam('cate_name');
         if ($frmCate->isValid($_POST)) {
             $mdlCate = new Application_Model_DbTable_Category();
             $result = $mdlCate->createCate($cateName, BLOGGER_ID);
             if ($result) {
                 $cache = Zend_Registry::get('cache');
                 $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('artcatebox'));
                 // redirect to the index action
                 //$this->_redirect ( '/category/index' );
                 $this->_forward('index');
             }
         }
     }
     if ($this->_request->getParam('pid')) {
         $pelem = $frmCate->createElement('hidden', 'pid');
         $pelem->setValue($this->_request->getParam('pid'));
         $frmCate->addElement($pelem);
     }
     $frmCate->setAction('/' . BLOGGER_NAME . '/category/create');
     $this->view->form = $frmCate;
 }
 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');
 }
示例#4
0
 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');
 }