Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.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
Symfony2条令自定义存储库类[语义错误]第0行,第102列_Symfony_Doctrine Orm - Fatal编程技术网

Symfony2条令自定义存储库类[语义错误]第0行,第102列

Symfony2条令自定义存储库类[语义错误]第0行,第102列,symfony,doctrine-orm,Symfony,Doctrine Orm,我在“pw WHERE pw.startdate”附近的第102列第0行收到此错误[语义错误]:错误:“pw”已定义。这就是我所拥有的: public function findBystartdateAndenddate($startdate, $enddate) { return $this ->createQueryBuilder('pw') ->select('pw') ->from ('comtwclagripayrollBundl

我在“pw WHERE pw.startdate”附近的第102列第0行收到此错误[语义错误]:错误:“pw”已定义。这就是我所拥有的:

  public function findBystartdateAndenddate($startdate, $enddate)
{
   return $this
    ->createQueryBuilder('pw')
     ->select('pw')
     ->from ('comtwclagripayrollBundle:Payrollweek','pw')
     ->where ('pw.startdate = :startdate and pw.enddate = :enddate')
    ->setParameter('startdate', $startdate)
    ->setParameter('enddate', $enddate)
    ->getQuery()
    ->getResult();

请从('comtwclagripayrollBundle:Payrollweek','pw')中删除
->
。因为您已经可以使用
->createQueryBuilder('pw')
为当前存储库创建对象

public function findBystartdateAndenddate($startdate, $enddate)
{
   return $this
     ->createQueryBuilder('pw')
     ->select('pw')
     ->where ('startdate = :startdate and enddate = :enddate')
     ->setParameter('startdate', $startdate)
     ->setParameter('enddate', $enddate)
     ->getQuery()
     ->getResult();
这应该行得通

->from ('comtwclagripayrollBundle:Payrollweek')
如果您想尝试DQL:

$query =$this->_em->createQuery('select a, DATE_DIFF(startdate, enddate) from "" ');


public function getByDate(\Datetime $date)
{
    $from = new \DateTime($date->format("Y-m-d")." 00:00:00");
    $to   = new \DateTime($date->format("Y-m-d")." 23:59:59");

    $qb = $this->createQueryBuilder("e");
    $qb
        ->andWhere('e.date BETWEEN :from AND :to')
        ->setParameter('from', $from )
        ->setParameter('to', $to)
    ;
    $result = $qb->getQuery()->getResult();

    return $result;
}
您可以尝试以下方法: 您的错误是两次使用(
->createQueryBuilder('pw')
中的
pw
和('comtwclagripayrollBundle:Payrollweek','pw'))

您还可以在
控制器中调用标准f.e:

$this->getDoctrine()->getRepository('YourFooBundle:YourEntity')->findBy(array('startdate' => $startdate, 'enddate' => $enddate));

好的,谢谢,但我不想有日期差异。我希望它们匹配。没关系,你只想比较2个日期,我想你需要转换日期,因为数据库中的日期和php中的日期格式不一样。
公共函数findBystartdateAndenddate($startdate,$enddate)
在存储库中的何处使用?是的,这是一个自定义存储这就是问题所在。
public function findBystartdateAndenddate($startdate, $enddate)
{
   return $this
       ->createQueryBuilder('pw')
       ->select('pw')
       ->where ('pw.startdate = :startdate')
       ->andWhere('pw.enddate = :enddate')
       ->setParameter('startdate', $startdate)
       ->setParameter('enddate', $enddate)
       ->getQuery()
       ->getResult();
}
$this->getDoctrine()->getRepository('YourFooBundle:YourEntity')->findBy(array('startdate' => $startdate, 'enddate' => $enddate));