Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 无原因命名的数组_Arrays_Symfony_Doctrine - Fatal编程技术网

Arrays 无原因命名的数组

Arrays 无原因命名的数组,arrays,symfony,doctrine,Arrays,Symfony,Doctrine,我调用一个存储库方法并在其中传递一个数组作为参数。但是数组是以第一个参数命名的,我不明白为什么 这是电话: /** * @param $month * @param $year * @return Conges[] */ public function getAllCongesPayes($year, $month) { return $this->congesRepository->getNbCongesByMonth(array('year' => $yea

我调用一个存储库方法并在其中传递一个数组作为参数。但是数组是以第一个参数命名的,我不明白为什么

这是电话:

/**
 * @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');
如果有人能解释为什么会这样,那就太棒了


提前谢谢。

好吧,我真的很笨,两分钟后就明白了。。。对不起,我的帖子

答案如下:

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;
}
需要在参数中传递数组。我不知道我为什么那样做。
不管怎样,问题解决了

在我看到这个之前,我正要回答。实际上,我认为与其将
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),因为这样可以更好地公开数组的参数。哦,是的,很好:)事实上,值得问一下^^谢谢!