public function createAction(Request $request)
 {
     $category = new Category();
     $em = $this->getDoctrine()->getManager();
     $ct = new CategoryController();
     $categorys = $ct->allCategoryAction($em);
     $categor = array();
     foreach ($categorys as $value) {
         foreach ($value as $val) {
             $arr = (array) $val;
             $categoryId = array_shift($arr);
             $categoryName = array_shift($arr);
             $categor += [$categoryId => $categoryName];
         }
     }
     $form = $this->createForm(new CategoryType(), $category);
     $form->add('categoryParent', 'choice', array('label' => 'Выберете раздел', 'multiple' => false, 'choices' => $categor, 'attr' => array('style' => 'width:300px', 'customattr' => 'customdata')));
     $form->add('submit', 'submit', array('label' => 'Создать Раздел'));
     $form->handleRequest($request);
     if ($request->getMethod() == 'POST') {
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $em->persist($category);
             $em->flush();
             // выполняем прочие действие, например, сохраняем задачу в базе данных
             return $this->redirect($this->generateUrl('blog_category_homepage'));
         }
         echo "Форма не валидна";
     }
     return $this->render('BlogArticleBundle:Category:new.html.twig', array('category' => $category, 'createform' => $form->createView()));
 }
 public function editAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $article = $em->getRepository('BlogArticleBundle:Article')->find($id);
     if (!$article) {
         throw $this->createNotFoundException('article not found');
     }
     // var_dump($article); die;
     $editform = $this->createForm(new ArticleType(), $article);
     /////////////////////////////////
     $ct = new CategoryController();
     $category = $ct->allCategoryAction($em);
     $categorys = array();
     foreach ($category as $value) {
         foreach ($value as $val) {
             $arr = (array) $val;
             $categoryId = array_shift($arr);
             $categoryName = array_shift($arr);
             $categorys += [$categoryId => $categoryName];
         }
     }
     //var_dump($categorys); die;
     $editform->add('articleCategoryId', 'choice', array('label' => 'Выберете раздел', 'multiple' => false, 'choices' => $categorys, 'attr' => array('style' => 'width:300px', 'customattr' => 'customdata')));
     //////////////////////////////////////
     $editform->add('submit', 'submit', array('label' => 'Изменить статью'));
     $editform->handleRequest($request);
     if ($editform->isValid()) {
         // выполняем прочие действие, например, сохраняем задачу в базе данных
         $em->flush();
         return $this->redirect($this->generateUrl('blog_article_post', array('id' => $id)));
     }
     return $this->render('BlogArticleBundle:Article:edit.html.twig', array('categorys' => $categorys, 'article' => $article, 'editform' => $editform->createView()));
 }