0
의 객체를 반환 안 :Symfony2 + 교리 + 저장소 :이 기능은 내 저장소에이 기능을 대신 배열
public function findLatestFeeAsigned($company_id) {
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('c', 'chw');
$qb->from('Configuration\FeeBundle\Entity\Fee', 'c');
$qb->leftJoin('Company\ApprovalBundle\Entity\CompanyHasWtax', 'chw', \Doctrine\ORM\Query\Expr\Join::WITH, 'c.id = chw.wtax');
$qb->where('chw.company = ?1');
$qb->orderBy('chw.created', 'ASC');
$qb->setMaxResults(1);
$qb->setParameter(1, $company_id);
return $qb->getQuery()->getResult();
}
그리고 나는 이런 식으로 내 컨트롤러에서 호출 :
$entityCurrentFee = $em->getRepository('ApprovalBundle:CompanyHasWtax')->findLatestFeeAsigned($id);
여기서 $id
은 요청 매개 변수입니다. 그럼으로 약간의 열 값을 얻을려고 :
$entityCurrentFee->getId();
을하지만 $entityCurrentFee
그 이유입니다, 객체 아니라고 말하는 오류가 발생했습니다? 당신이 기본 키에 의해 조회하거나 하나의 개체를 검색 할 것으로 예상하는 경우
getQuery를 던졌습니다 조심 사용해야합니다() -> getOneOrNullResult() 피할 수 그것이 그가 원하는 것일 경우 결과가 예외가 아닙니다. – Cerad
그래, 그걸 잊어 버렸어. –