I create a MONTH function to extract month of a date.
I want to GROUP BY the result with these query:
SELECT MONTH(p.publicationDateStart) AS archive
FROM ApplicationSonataNewsBundle:Post p
GROUP BY archive
But it gives me error:
An exception has been thrown during the rendering of a template
("Notice: Undefined index: archive in
/home/kiddo/Code/apache2/work/ibctal.dev/vendor/doctrine/orm/lib/Doctrine/ORM/Query
/SqlWalker.php line 2197") in ApplicationSonataNewsBundle:Post:archive.html.twig
at line 10.
How can I fix this problem.
For reference I found this information of doctrine's commit: https://github.com/doctrine/doctrine2/commit/2642daa43851878688d01625f272ff5874cac7b2:
EDIT :
Here is the Controller Code
namespace Application\Sonata\NewsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Doctrine\ORM\Query\ResultSetMapping;
class SidebarController extends Controller
{
public function archiveAction()
{
$em = $this->getDoctrine()->getManager();
$dql = "SELECT
MONTH(p.publicationDateStart) AS archive,
p.publicationDate AS HIDDEN archiveDate
FROM
ApplicationSonataNewsBundle:Post p
GROUP BY
MONTH(archiveDate)";
$query = $em->createQuery($dql);
$paginator = $this->get('knp_paginator');
$pager = $paginator->paginate($query, $this->get('request')->query->get('page', 1), 10);
return $this->render('ApplicationSonataNewsBundle:Sidebar:archive.html.twig', array(
'archives' => $pager
));
} }
And FYI, I use 2.3.1-DEV version