示例#1
0
 public function addArticleAction(Request $request)
 {
     $form = $this->createFormBuilder()->add('title', 'text')->add('slug', 'hidden')->add('author', 'text')->add('tags', 'text')->add('content', 'ckeditor', array('input_sync' => true))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $baseArticle = $this->getDoctrine()->getRepository('ArticleBundle:Article')->findBySlug($data['slug']);
         if ($baseArticle == FALSE) {
             $article = new Article();
             $article->setTitle($data['title']);
             $article->setSlug($data['slug']);
             $article->setAuthor($data['author']);
             $article->setTags($data['tags']);
             $article->setContent($data['content']);
             $em = $this->getDoctrine()->getManager();
             $em->persist($article);
             $em->flush();
             return $this->redirect('/' . $data['slug']);
         } else {
             $form->addError(new FormError("Tytuł ten występuje już w bazie wiedzy!"));
         }
     }
     return $this->render('ArticleBundle:Panel:form.html.twig', ['form' => $form->createView(), 'title' => 'Dodaj nowy artykuł']);
 }