public function showAction($category, $slug) { /*$repository = $this->getDoctrine()->getRepository('AppBundle:ArticleCategory'); // 1st way $categoryRepo = $repository->findOneBy(['slug' => $category]); // $categoryRepo = $repository->findOneBySlug($slug); $articles = $categoryRepo->getArticles(); // $article = $articles->findOneBy(['title' => $slug]); // print_r($articles->getValues()); // filtering foreach ($articles as $item) { if ($item->getSlug() == $slug) { $article = $item; } }*/ // 2nd way /*$queryBuilder = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); $queryBuilder->select('a') ->from('AppBundle:Article', 'a') ->innerJoin('a.category', 'ac') ->where('ac.slug=:category_slug', 'a.slug=:article_slug') ->setParameter(':category_slug', $category) ->setParameter(':article_slug', $slug); $article = $queryBuilder->getQuery()->getSingleResult();*/ // 3rd way // $entityManager = $this->get('doctrine.orm.entity_manager'); // $repository = $entityManager->getRepository('AppBundle:ArticleCategory'); // $entityManager = $this->get('doctrine.orm.entity_manager'); $repository = $this->getDoctrine()->getRepository('AppBundle:ArticleCategory'); $articleProvider = new ArticleProvider($repository); $article = $articleProvider->get($category, $slug); return $this->render('RenaissanceBundle:Article:show.html.twig', array('article' => $article)); }
public function getCategoryArticleAction($category, $slug) { $repository = $this->getDoctrine()->getEntityManager()->getRepository('AppBundle:ArticleCategory'); $articleProvider = new ArticleProvider($repository); $article = $articleProvider->get($category, $slug); $view = $this->view($article, 200); return $this->handleView($view); }