-1
訪問自定義查詢這是我得到一個隨機產品查詢:在Symfony2的庫
public function getRelatedProducts()
{
$em = $this->getDoctrine()->getManager();
$max = $em->createQuery('SELECT MAX(p.id) FROM GlassShopBundle:Product p')->getSingleScalarResult();
return $em->createQuery('SELECT q FROM GreenMonkeyDevGlassShopBundle:Product p WHERE p.id >= :rand ORDER BY p.id ASC')
->setParameter('rand',rand(0,$max))
->setMaxResults(1)
->getSingleResult()
->getResults();
}
我得到一個Undefined method 'getRelatedByCategory'. The method name must start with either findBy or findOneBy!
錯誤,這對我來說,因爲其他查詢甲肝工作對我來說是陌生的,我還沒有真正偏離。有什麼想法嗎?
方法名爲'getRelatedProducts',你調用'getRelatedByCategory'那麼最新的問題是什麼? –
只是一件相關的事情:它因爲教義中所謂的「魔法發現者」而呻吟着「findBy」和「findOneBy」。 「magic finders」在PHP __call函數中處理,當您調用不可訪問或不存在的方法時,最終會出現這種情況。該消息可能會使用一個更少的誤導...... –