2016-05-02 4 views
1

Я вызываю метод репозитория и передаю ему массив для параметров. Но массив назван в честь первого параметра, и я не понимаю, почему.массив, названный без причины

Вот вызов:

/** 
* @param $month 
* @param $year 
* @return Conges[] 
*/ 
public function getAllCongesPayes($year, $month) 
{ 
    return $this->congesRepository->getNbCongesByMonth(array('year' => $year, 'month' => $month, 'cngPaye' => true)); 
} 

А ошибки я могу видеть, что:

array('year' => array('year' => '2016', 'month' => '05', 'cngPaye' => true))) 

И, конечно, это говорит «Отсутствует аргумент 2», потому что только один массив в нем.

Вот это хранилище метод:

public function getNbCongesByMonth($year, $month, $conge){ 
$qb = $this->createQueryBuilder('e'); 

$listOfEntities = $qb 
    ->select('count(e) as nb') 
    // ->leftjoin('e.cngUsrLogin', 'u') 
    ->where(
     $qb->expr()->like('e.cngDateDebut', 
      $qb->expr()->literal($year.'-'.$month.'-%') 
     ) 
    ) 
    ->andWhere('e.congesPayes = :conge') 
    // ->andWhere('u.usrGestionCra = 1') 
    // ->groupBy('e') 
    ->setParameter('conge', $conge) 
    ->getQuery() 
    ->getResult(); 
return $listOfEntities; 
} 

и вызов в контроллере:

$this->congesService = $this->get("intranet.conges_service"); 
    $nbCongesPayes = $this->congesService->getAllCongesPayes('2016', '05'); 

Если кто-то может объяснить, почему это происходит, что было бы удивительным.

Заранее спасибо.

ответ

1

ОК, я действительно тупой и понял это через 2 минуты после ... Извините за пост ...

Вот ответ:

public function getNbCongesByMonth($array){ 
$qb = $this->createQueryBuilder('e'); 

$listOfEntities = $qb 
    ->select('count(e) as nb') 
    // ->leftjoin('e.cngUsrLogin', 'u') 
    ->where(
     $qb->expr()->like('e.cngDateDebut', 
      $qb->expr()->literal($array['year'].'-'.$array['month'].'-%') 
     ) 
    ) 
    ->andWhere('e.cngPaye = :conge') 
    // ->andWhere('u.usrGestionCra = 1') 
    // ->groupBy('e') 
    ->setParameter('conge', $array['cngPaye']) 
    ->getQuery() 
    ->getResult(); 
return $listOfEntities; 
} 

Необходимо, чтобы передать массив в параметры. Я не знаю, почему я это сделал. Во всяком случае это решение

+0

Я уже собирался ответить, прежде чем увидел это. На самом деле, я думаю, вместо замены 'getNbCongesByMonth ($ year, $ month, $ conge)' на 'getNbCongesByMonth ($ array)', было бы лучше изменить 'return $ this-> congesRepository-> getNbCongesByMonth (array (' year '=> $ year,' month '=> $ month,' cngPaye '=> true)); 'to' return $ this-> congesRepository-> getNbCongesByMonth ($ year, $ month, true); ', так как это более подробно отображает параметры массива. – Terenoth

+0

О да, хорошо :) На самом деле стоило спросить ^^ Спасибо! –

Смежные вопросы