2016-05-02 15 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がありません」と言っています。これはそれは素晴らしいだろうなぜ起こるか、誰かが説明できる場合

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

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; 
} 

とコントローラでのコール:ここ

は、リポジトリ方式です。

ありがとうございます。

答えて

1

OK、私は本当にばかだし、それに後...ポストのため申し訳ありませんが、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( ' $ this-> congesRepository-> getNbCongesByMonth($ year、$ month、true); 'を返します。これは、配列のパラメータをよりよく公開します。 – Terenoth

+0

ああええ、素敵:)実際にそれは価値があった^ ^ありがとう! –

関連する問題