O'Reilly logo

Extending Symfony2 Web Application Framework by Sébastien Armand

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom DQL functions

Doctrine can be adapted to many different database vendors such as MySQL, PostgreSQL, and others. To achieve this and still be able to take advantage of the specifics of each underlying platform, Doctrine is designed in such a way that it is easy to define your own custom SQL functions.

We will take advantage of this for our geolocation. In the first chapter, we decided that the home page would only display events within 25 kilometers (which roughly translates to 0.3 in terms of latitude and longitude). To do so, we defined a box of coordinates around a given point and then used it in the SQL code.

However, an actual distance between two points (in a Cartesian plan) is calculated by the following formula:

The preceding formula ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required