Witam, od około miesiąca pracuje z symfony i podczas tworzenia pierwszej większej aplikacji wyświetla mi się błąd:
Too few parameters: the query defines 1 parameters but you only bound 0
500 Internal Server Error - QueryException
Mój kod wygląda następująco:
<?php
namespace PageBundle\Repository;
use Doctrine\ORM\EntityRepository;
class VideoRepository extends EntityRepository
{
public function getQueryBuilder(array $params = array()){
$qb= $this->createQueryBuilder('v')
->select('v, c, t')
->leftJoin('v.category', 'c')
->leftJoin('v.tags', 't');
if(!empty($params['status'])){
if('published' == $params['status']){
$qb -> where('v.publishedDate <= :currDate AND v.publishedDate IS NOT NULL')
->setParameter('currentDate', new \DateTime());
}else if ('unpublished' == $params['status']){
$qb -> where('v.publishedDate > :currDate OR v.publishedDate IS NULL')
->setParameter('currentDate', new \DateTime());
}
}
if (!empty($params['orderBy'])){
$orderDir = !empty($params['orderDir']) ? $params['orderDir'] : NULL;
$qb->orderBy($params['orderBy'], $orderDir);
}
return $qb;
}
}
Oraz kontroler:
public function indexAction($page)
{
$PostRepo = $this->getDoctrine()->getRepository('PageBundle:Video');
$qb = $PostRepo -> getQueryBuilder(array(
'status' => 'published',
'orderBy' => 'v.publishedDate',
'orderDir' => 'DESC'
));
$paginator = $this -> get('knp_paginator');
$pagination = $paginator->paginate($qb, $page, $this->itemsLimit);
return array('pagination' => $pagination);
}
Jestem dopiero początkujący jeśli chodzi o doświadzenie z symfony i nie wiem gdzie zrobiłem błąd. Przeglądałem stacka, ale mało z tego rozumiem.
Dzięki za pomoc, Else.