我是教义上的新手。我正在使用具有学说的Codeigniter框架,并且我会得到此错误
A PHP Error was encountered
Severity: Warning
Message: get_class() expects parameter 1 to be object, integer given
Filename: Expr/Base.php
Line Number: 92
当我尝试将整数变量插入模型函数中的参数
public function selectsingle($id){
$qb = $this->em->createQueryBuilder();
$query = $qb->select('p.name', 'p.email', 'p.subject', 'p.message')
->from('PdContact', 'p')
->where('p.id', $id);
$result = $query->getQuery()->getResult();
echo "<pre>";
print_r($result);
exit;
}
我如何将任何整数传递到Where子句。
我在添加 ->setParameter("id", $id)
并将子句更改为 ->where('p.id = :id')
public function selectsingle($id){
$qb = $this->em->createQueryBuilder();
$query = $qb->select('p.name', 'p.email', 'p.subject', 'p.message')
->from('PdContact', 'p')
->where('p.id = :id')
->setParameter("id", $id);
return $result = $query->getQuery()->getResult();
}