public function editAction()
 {
     $auth = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     if (!$auth->hasIdentity()) {
         return $this->redirect()->toRoute('home');
     }
     $id = (int) $this->getEvent()->getRouteMatch()->getParam('id');
     //Si l'Id est vie on redirige vers l'ajout
     if (!$id) {
         return $this->redirect()->toRoute('page', array('action' => 'add'));
     }
     //Sinon on charge la page correspondant à l'Id
     $page = $this->getEntityManager()->find('Cms\\Entity\\Page', $id);
     $form = new PageForm();
     //Initialise la liste des categories
     $categories = $this->getEntityManager()->getRepository('Cms\\Entity\\Category')->findAll();
     $options = array("" => "");
     foreach ($categories as $cat) {
         $options[$cat->getCtgrId()] = $cat->getCtgrName();
     }
     $form->setCategories($options);
     $form->bind($page);
     $form->get('ctgr_id')->setValue($page->getCategory() != null ? $page->getCategory()->getCtgrId() : '');
     $menus = $this->getEntityManager()->getRepository('Cms\\Entity\\Menu')->findAll();
     $articles = $this->getEntityManager()->getRepository('Cms\\Entity\\Article')->findAll();
     $options = array("" => "");
     foreach ($menus as $menu) {
         $options[$menu->getMenuId()] = $menu->getMenuName();
     }
     //        $form->setMenus($options);
     //        $form->get('menu_id')->setValue($page->getMenu() != null ? $page->getMenu()->getMenuId() : '');
     $request = $this->getRequest();
     //Vérifie le type de la requête
     if ($request->isPost()) {
         $form->setData($request->getPost());
         //Contrôle les champs
         if ($form->isValid()) {
             $categoryId = $form->get('ctgr_id')->getValue();
             $form->bindValues();
             $category = null;
             if (!empty($categoryId)) {
                 $category = $this->getEntityManager()->find('Cms\\Entity\\Category', $categoryId);
             }
             $page->setCategory($category);
             $this->getEntityManager()->flush();
             //Redirection vers la liste des pages
             return $this->redirect()->toRoute('cms/default', array('controller' => 'page', 'action' => 'index'));
         }
     }
     return array('id' => $id, 'form' => $form);
 }
 /**
  * Edit page
  * 
  * 
  * @access public
  * @uses PageForm
  * 
  * @return ViewModel
  */
 public function editAction()
 {
     $variables = array();
     $id = $this->params('id');
     $pageModel = $this->getServiceLocator()->get('CMS\\Model\\Page');
     $query = $this->getServiceLocator()->get('wrapperQuery');
     $pageObj = $query->find('CMS\\Entity\\Page', $id);
     $request = $this->getRequest();
     if (!$request->isPost()) {
         // extract body data to be able to display it in it's natural form
         $pageObj->body = $pageObj->getBody();
     }
     $options = array();
     $options['query'] = $query;
     $form = new PageForm(null, $options);
     // removing unpublish button in case of already unpublished page
     if ($pageObj->getStatus() == \Utilities\Service\Status::STATUS_INACTIVE) {
         $form->remove(FormButtons::UNPUBLISH_BUTTON);
         $form->getInputFilter()->remove(FormButtons::UNPUBLISH_BUTTON);
     }
     $form->bind($pageObj);
     if ($request->isPost()) {
         $data = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setInputFilter($pageObj->getInputFilter($query));
         $form->setData($data);
         $pageModel->setFormRequiredFields($form, $data, true);
         if ($form->isValid()) {
             $pageModel->save($pageObj, $data, true);
             $url = $this->getEvent()->getRouter()->assemble(array('action' => 'index'), array('name' => 'cmsPage'));
             $this->redirect()->toUrl($url);
         }
     }
     $formViewHelper = new FormViewHelper();
     $this->setFormViewHelper($formViewHelper);
     $variables['id'] = $id;
     $variables['pageForm'] = $this->getFormView($form);
     $variables['pressReleaseType'] = PageTypes::PRESS_RELEASE_TYPE;
     return new ViewModel($variables);
 }