public function addAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'index', 'action' => 'index'));
     }
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $article = new Article();
     try {
         $repository = $entityManager->getRepository('CsnCms\\Entity\\Article');
         $parent = $repository->findOneBy(array('artcId' => $id));
         $article->setParent($parent);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'index', 'action' => 'index'));
     }
     $form = $this->getForm($article, $entityManager, 'Add');
     $form->bind($article);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $request->getPost();
         // uncooment and fix if you want to control the date and time
         //			$post->artcCreated = $post->artcCreatedDate . ' ' . $post->artcCreatedTime;
         $form->setData($post);
         if ($form->isValid()) {
             $this->prepareData($article);
             $entityManager->persist($article);
             $entityManager->flush();
             return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'translation', 'action' => 'index', 'id' => $id), true);
         }
     }
     return new ViewModel(array('form' => $form));
 }
Exemple #2
0
 /**
  * Add Child
  *
  * @param CsnCms\Entity\Article $child
  * @return Article
  */
 public function addChild(\CsnCms\Entity\Article $child)
 {
     $child->setParent($this);
     // synchronously updating inverse side
     $this->children[] = $child;
     return $this;
 }