コード例 #1
0
 public function addAction()
 {
     $form = new MenuForm();
     $resultSet = $this->getEntityManager()->getRepository('Cms\\Entity\\Category')->findAll();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new MenuFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             unset($data['submit']);
             $this->getMenusTable()->insert($data);
             return $this->redirect()->toRoute('cms/default', array('controller' => 'menu', 'action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form, 'categories' => $resultSet));
 }
コード例 #2
0
 /**
  * Edit menu
  * 
  * 
  * @access public
  * @uses MenuForm
  * 
  * @return ViewModel
  */
 public function editAction()
 {
     $variables = array();
     $id = $this->params('id');
     $query = $this->getServiceLocator()->get('wrapperQuery');
     $menuObj = $query->find('CMS\\Entity\\Menu', $id);
     $form = new MenuForm();
     $form->bind($menuObj);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost()->toArray();
         $form->setInputFilter($menuObj->getInputFilter($query));
         $form->setData($data);
         if ($form->isValid()) {
             $query->save($menuObj);
             $url = $this->getEvent()->getRouter()->assemble(array('action' => 'index'), array('name' => 'cmsMenu'));
             $this->redirect()->toUrl($url);
         }
     }
     $variables['menuForm'] = $this->getFormView($form);
     return new ViewModel($variables);
 }