Reputation: 1058
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));
}
Upvotes: 4
Views: 1356
Reputation: 9103
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.
Upvotes: 1