-1

这是我获取随机产品的查询:

 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!错误,这对我来说很奇怪,因为其他查询对我有用,而且我并没有真正偏离。有什么想法吗?

4

1 回答 1

1

可能是被调用函数名中的拼写错误。方法命名getRelatedProducts,你调用getRelatedByCategory

于 2013-07-01T13:54:16.830 回答