2016-12-07 75 views
0

我是新的學說ORM。我使用笨教義框架,我得到這個錯誤我怎麼能通過整數變量裏面的條款裏的條款querybuilder

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子句中的任意整數。

+0

如果你已經找到了解決辦法,請寫一個答案,並接受它後得到了解決。 – pckill

回答

0

我加入->setParameter("id", $id)和不斷變化的where子句->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(); 
}