protected function loadTags(ObjectManager $manager) { for ($i = 0; $i < self::TAG_NUMS; $i++) { $tag = new Tag(); $tag->setName($this->faker->word); $manager->persist($tag); } $manager->flush(); }
/** * @param $page * @param Tag|null $tag * @param Category|null $category * @return Response */ public function listAction($page, Tag $tag = null, Category $category = null) { if ($tag !== null) { $query = $tag->getPosts(); $route = 'tag'; } else { if ($category !== null) { $query = $category->getPosts(); $route = 'category'; } else { $query = $this->getPostRepository()->findBy([], ['createdAt' => 'DESC']); $route = 'index'; } } /** @var $paginator \Knp\Component\Pager\Paginator */ $paginator = $this->get('knp_paginator'); /** @var \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination $posts */ $posts = $paginator->paginate($query, $page, Post::PAGE_ITEMS); $posts->setUsedRoute("blog_{$route}_paginated"); return $this->render('TaichiBlogBundle:Blog:index.html.twig', ['posts' => $posts, 'tag' => $tag, 'category' => $category]); }
/** * Add tag * * @param \Taichi\BlogBundle\Entity\Tag $tag * * @return Post */ public function addTag(Tag $tag) { $tag->addPost($this); $this->tags[] = $tag; return $this; }