CackePHP 3 formatResults() ORDER by field created dynamically

梦想的初衷 提交于 2019-12-02 10:03:24

You can sort by a field calculated in php, but it will not work for pagination, since for doing the sorting you need all the records from the database. You need to create an equivalent logic that runs in SQL so you can sort.

Check this plugin that can help you calculate the distances and sort by them https://github.com/dereuromark/cakephp-geo/

The is the find('distance') custom finder that you can dynamically add to your table when using the provided behavior. https://github.com/dereuromark/cakephp-geo/blob/master/src/Model/Behavior/GeocoderBehavior.php#L223

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!