Для получения доступа к Entity Manager из статического (static) метода, что позводин нам использовать произвольный sql запрос. На самом деле все довольно просто, необходимо в любой из Бандлов (Bundle) добавить следующие методы:
| |
| class AcmeDemoBundle extends Bundle |
| { |
| private static $containerInstance = null; |
| |
| public function setContainer(\Symfony\Component\DependencyInjection\ContainerInterface $container = null) |
| { |
| parent::setContainer($container); |
| self::$containerInstance = $container; |
| } |
| |
| public static function getContainer() |
| { |
| return self::$containerInstance; |
| } |
| } |
и затем в нужном нам методе, использовать например такой код:
| |
| static function getData($id) { |
| |
| |
| $em = WyngspanBundle::getContainer()->get('doctrine')->getManager(); |
| |
| |
| |
| $user = $em->getRepository('Users')->find($id); |
| |
| |
| $where = ' WHERE id= '.$id |
| $sql = ' |
| SELECT id, name |
| FROM users' |
| . $where; |
| $query = $em->getConnection()->query($sql); |
| |
| $user= $query->fetchAll();; |
| |
| return $user; |
| } |
Также можно использовать QueryBuldier, DQL и т д, все что душе угодно...