You should put that function inside a custom repository for the Page entity
While the Entities are the objects you are storing, the Repository is the class that provides methods to access/load those objects, eg when you call $em->getRepository('Entities\Page')->find($page_id);
, you call the find()
method on your Page repository and it's its job to find it for you.
Doctrine provides a default repository for each entity (with the various find*()
methods, ...), but you can provide a custom one where you can add your own method, such as getByPath()
.
Symfony 2 - Database and Doctrine - Custom Repository Classes