Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony OrderBy计算属性实体_Symfony_Doctrine Orm_Entitymanager - Fatal编程技术网

Symfony OrderBy计算属性实体

Symfony OrderBy计算属性实体,symfony,doctrine-orm,entitymanager,Symfony,Doctrine Orm,Entitymanager,实体: class Pharmacie{ public $distance; public function getDistance() { // calculate distance here return $distance; } } 在控制器中: public function listePharmsGeoAction() { $em = $this->getDoctrine()-&g

实体:

 class Pharmacie{    
      public $distance;

     public function getDistance() {
          // calculate distance here 
          return $distance; 
    }

}
在控制器中:

 public function listePharmsGeoAction()
{
    $em = $this->getDoctrine()->getEntityManager();


    $pharmas = $em->getRepository('CentraleFrontBundle:Pharmacie')
                   ->createQueryBuilder('o')
                   ->orderBy('o.distance','ASC')
                   ->getQuery()
                   ->getResult();



     return $this->render('CentraleFrontBundle:SiteFront:listePharms.html.twig', array(
        'pharmas' => $pharmas));
}
错误:[语义错误]第0行,第65列“距离ASC”附近:错误:Class Centrale\FrontBundle\Entity\Pharmacie没有名为“距离”的字段或关联
  • 直接在控制器中创建查询是一种不好的做法,您应该在存储库中创建函数
  • 距离财产应受到保护,或为私人财产,而非公共财产
  • 你的地图在哪里

  • 您的药房实体中没有距离属性。。。问题是什么?假设你的回答是bat距离没有表列到映射是用地址和ip filedOk计算的,所以这是正常的,你不能按不存在的列排序。我如何按计算适当性排序?