나는 날짜와 해당 게시물에 대한 사용 클릭이 나타나는 블로그 사이트에 대한 블로그 아카이브를 설정하려고 노력하고 있습니다. (이미지 참조) 모든 블로그 게시물을 검색하고 날짜순으로 정렬해야하지만 그 이후의 단계는 나에게 안개가된다는 것을 이해합니다. 해당 데이터를 가져 와서 월/연도별로 정렬하고 템플릿에 전달하면 문제가있는 부분입니다.Symfony2 - 블로그 아카이브 설정
누군가 내가 잘못하고있는 것을 밝히거나 간단한 예제를 제공 할 수 있습니까?
내가 지금까지 가지고 :
public function archiveAction()
{
$em = $this->getDoctrine()->getManager();
// $query = $em->getRepository('AcmeProjectBundle:Blog')
// ->findAll();
$blogs = $em->getRepository('AcmeProjectBundle:Blog')
->getLatestBlogs();
if (!$blogs) {
throw $this->createNotFoundException('Unable to find blog posts');
}
foreach ($blogs as $post) {
$year = $post->getCreated()->format('Y');
$month = $post->getCreated()->format('F');
$blogPosts[$year][$month][] = $post;
}
// exit(\Doctrine\Common\Util\Debug::dump($month));
return $this->render('AcmeProjectBundle:Default:archive.html.twig', array(
'blogPosts' => $blogPosts,
));
}
좋습니다. 너 어디서 곤경에 처한거야? – DonCallisto
사용자가 해당 날짜와 관련된 적절한 게시물을 한달에 클릭 할 때 적절한 날짜로 나뭇 가지 작업을 설정하는 다음 단계입니다. –