public function addAction()
 {
     $menuForm = new categoryForm();
     $id = $this->params()->fromRoute('id');
     //set form values
     if ($id) {
         $menu = $this->catModel->findOneBy(array('id' => $id));
         $menuForm->get('id')->setValue($menu->getId());
         $menuForm->get('name')->setValue($menu->getName());
         $menuForm->setAttribute('action', '/admin/category/add/' . $id);
     }
     if ($this->getRequest()->isPost()) {
         $data = $this->params()->fromPost();
         //validate form, comming soon for form->getData
         //$menuForm->setData($data);
         //if($menuForm->isValid()){
         //$data = $menuForm->getData();
         $id = $data['id'];
         if ($id) {
             $category = $this->catModel->findOneBy(array('id' => $id));
             $category->setName($data['name']);
             $this->catModel->edit($category);
             $this->flashMessenger()->addSuccessMessage($this->translator->translate("Update Success"));
             return $this->redirect()->toRoute('admin/child', array('controller' => 'category'));
         } else {
             $category = new Categories();
             $category->setName($data['name']);
             $category->setIsdelete(0);
             $this->catModel->insert($category);
             $this->flashMessenger()->addSuccessMessage($this->translator->translate("Insert Success"));
             return $this->redirect()->toRoute('admin/child', array('controller' => 'category'));
         }
     }
     return new ViewModel(array('form' => $menuForm, 'title' => $this->translator->translate('Add New Category')));
 }
 public function addAction()
 {
     $request = $this->getRequest();
     $id = $this->params()->fromRoute('id');
     //insert
     if ($id == '') {
         if ($request->isPost()) {
             $cat = new Categories();
             $cat->setName($this->params()->fromPost('name'));
             $cat->setIsdelete(0);
             $catInserted = $this->modelCategories->insert($cat);
         }
         //insert new user
         //$this->redirect()->toRoute('admin/child',array('controller'=>'category'));
         return new ViewModel(array('title' => $this->translator->translate('Add new category')));
     } else {
         $cat = $this->modelCategories->findOneBy(array('id' => $id));
         if ($request->isPost()) {
             $idFormPost = $this->params()->fromPost('id');
             $cat = $this->modelCategories->findOneBy(array('id' => $idFormPost));
             $cat->setName($this->params()->fromPost('name'));
             $cat->setIsdelete(0);
             $this->modelCategories->edit($cat);
         }
         return new ViewModel(array('data' => $cat, 'title' => $this->translator->translate('Edit category') . ': ' . $cat->getName()));
     }
 }