public function addAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('cms/default', array('controller' => 'index', 'action' => 'index'));
     }
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $article = new Article();
     try {
         $repository = $entityManager->getRepository('Cms\\Entity\\Article');
         $parent = $repository->findOneBy(array('artcId' => $id));
         $article->setParent($parent);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('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('cms/default', array('controller' => 'translation', 'action' => 'index', 'id' => $id), true);
         }
     }
     return new ViewModel(array('form' => $form));
 }
 /**
  * {@inheritDoc}
  */
 public function setParent($parent)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setParent', array($parent));
     return parent::setParent($parent);
 }
Example #3
0
 /**
  * Add Child
  *
  * @param Cms\Entity\Article $child
  * @return Article
  */
 public function addChild(\Cms\Entity\Article $child)
 {
     $child->setParent($this);
     // synchronously updating inverse side
     $this->children[] = $child;
     return $this;
 }