我想從「Cours」表中獲取所有記錄,其中由表單提交的$speciality
的值是IN arrayColloction()
由每個返回類別Cours
的單個對象。我使用的下一行有那個結果(但遺憾的是它不工作):可捕獲的致命錯誤:類的對象...不能轉換爲字符串
public function andWhereSpeciality(QueryBuilder $qb, Speciality $speciality)
{
$qb
->andWhere($qb->expr()->in(':speciality','a.specialities'))
->setParameter('speciality', $speciality) ;
return $qb;
}
類Cours
有ManyToMany
關係就像下面的代碼:
/**
* @ORM\ManyToMany(targetEntity="BacUp\GeneralBundle\Entity\Speciality", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Assert\Count(min = 1, minMessage = "You have to choose at least one speciality")
*/
private $specialities;
執行返回以下錯誤:
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Catchable Fatal Error: Object of class BacUp\GeneralBundle\Entity\Speciality could not be converted to string in C:\wamp\www\Symfony\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Expr.php line 452" at C:\wamp\www\Symfony\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Expr.php line 452
現在我收到以下異常:[code] CRITICAL - 未捕獲到PHP異常Symfony \ Component \ Debug \ Exception \ UndefinedMethodException:「嘗試在C中的類」Doctrine \ ORM \ Query \ Expr「上調用方法」isMemberOf「 :\ wamp \ www \ Symfony \ src \ BacUp \ GeneralBundle \ Entity \ CoursRepository.php line 84.「在C:\ wamp \ www \ Symfony \ src \ BacUp \ GeneralBundle \ Entity \ CoursRepository.php第84行[/ code] – 2015-01-10 13:54:54
現在,它能正常工作......謝謝。 – 2015-01-10 14:15:00