Symfony2 Doctrine Custom Repository Class [语义错误]第0行,第102列

时间:2017-08-09 14:04:42

标签: symfony doctrine-orm

我收到此错误[语义错误]第0行,第102行附近' pw WHERE pw.startdate':错误:' 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();

4 个答案:

答案 0 :(得分:1)

 ->from ('comtwclagripayrollBundle:Payrollweek')

这应该工作

答案 1 :(得分:1)

<ListView fx:id="listView" prefHeight="${listView.parent.width}"/>

如果你想尝试DQL:

->from ('comtwclagripayrollBundle:Payrollweek')

答案 2 :(得分:1)

你可以试试这个: 您的错误是(pw->createQueryBuilder('pw')

中两次使用->from ('comtwclagripayrollBundle:Payrollweek','pw')
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();
}

您也可以在Controller来电标准f.e:

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

答案 3 :(得分:0)

请删除->from ('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();