4

I am trying this part in the Doctrine Documentation wherein you can:


Manually writing DQL

For you SQL buffs, we didn't forget about you. You can optionally write your DQL queries manually and parse them in to a Doctrine_Query instance or just execute them.

$dql = "FROM User u, u.Phonenumbers p";
$q = Doctrine_Query::create()->parseQuery($dql);

Or you can just execute them by using the query() method of Doctrine_Query.

$dql = "FROM User u, u.Phonenumbers p";
$q = Doctrine_Query::create()->query($dql);

Yet I'm having difficulties since I've encountered the following error:

Attempted to load class "Doctrine_Query" from namespace "AppBundle\Controller". Did you forget a "use" statement for another namespace?

Could you please help me with this?

<?php

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use AppBundle\Entity\TblProduct;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction()
    {
        $products = "SELECT * FROM TblProduct";
        $q = Doctrine_Query::create()->query($products);

        if (!$products) {
            throw $this->createNotFoundException(
                'No products registered yet.'
            );
        }
        return $this->render('default/index.html.twig', array('products' => $products));
    }
j0k
  • 22,600
  • 28
  • 79
  • 90
user123
  • 1,060
  • 3
  • 13
  • 29
  • Ahh so it's not part of Doctrine2 anymore? I was just trying this one. I'm still new to Symfony. :) – user123 Apr 27 '15 at 03:19
  • read this answer: http://stackoverflow.com/a/9945711/1055200 – b.b3rn4rd Apr 27 '15 at 03:23
  • Also, the particular error message is a namespace issue. $q = \Doctrine_Query... (note the back slash) would get you past it but don't use D1. – Cerad Apr 27 '15 at 11:33

1 Answers1

1

This is part of Doctrine 1.2 and not Doctrine 2.5. In the latest version you would just create queries in the Doctrine Query Language with createQuery().

<?php
$dql = "FROM User u, u.Phonenumbers p";
$query = $em->createQuery($dql);
$users = $query->getResult();

Alternatively you can write Native SQL.

oshell
  • 8,923
  • 1
  • 29
  • 47