cake如何在cake php3中找到地理位置之间的get_dinstance_in_miles



如何在cakefp 3 中找到geo_locations之间的get_distance_in_miles

通过使用类似cakephp2的字段而不是通过核心php查询。通过这种方法

$data = $this->Restaurant->find('all', array(
"fields" => array("get_distance_in_miles_between_geo_locations($lat,$long,Restaurant.latitude,Restaurant.longitude) as distance", "Restaurant.*,RestaurantsType.*"),
"ORDER BY" => 'DESC',
));

您的问题不是很清楚,您的代码会在cake2 中引发错误

无论如何,我猜你有一个用户定义的函数,你想使用它。在cake3中这样做的方法是:

或者你最好使用cakeSQL函数

$query = $this->Restaurants->find();
$query->select([
'distance' => $query->func()->get_distance_in_miles_between_geo_locations([
$lat,
$long,
'Restaurants.latitude' => 'identifier',
'Restaurants.longitude' => 'identifier'     
])
])

请注意,我已将Restaurant更改为Restaurants,将RestaurantsType更改为RestaurantsTypes,以遵循蛋糕3命名约定

最新更新