我们正在运行带有Postgres数据库的Cake
PHP v3.x.我需要选择一些纬度和经度与另一个点相距X距离的记录. PostGIS
has a function that does just this但似乎我必须正确的原始SQL查询才能使用它.
我不是在寻求帮助编写原始查询,但我正在寻找确认原始查询方法是否是在充分利用框架的同时使用此扩展的正确方法.我搜索并没有找到任何库来扩展CakePHP ORM以包含它.也许还有第三种选择,我没有想过.
[注意:这不起作用……]
public function fetch() { $maxMetersAway = 10 * 1000; $lat = $this->request->query['lat']; $lng = $this->request->query['lng']; $stops = $this->Stops->find('all') ->where("ST_DWithin( POINT($lng,$lat),POINT(Stops.lng,Stops.lat),$maxMetersAway") ->toArray(); $this->set(['stops'=>$stops,'_serialize' => true]); }