I try this part in the Doctrine Documentation in which you can:
Manually writing DQL
For you, SQL buffs, we have not forgotten about you. You can optionally record your DQL queries manually and parse them into an instance of Doctrine_Query, or simply execute them.
$dql = "FROM User u, u.Phonenumbers p";
$q = Doctrine_Query::create()->parseQuery($dql);
Or you can simply execute them using the query () method of Doctrine_Query.
$dql = "FROM User u, u.Phonenumbers p";
$q = Doctrine_Query::create()->query($dql);
But I'm having difficulties, as I ran into the following error:
Attempted to load the Doctrine_Query class from the AppBundle \ Controller namespace. Did you forget the "use" operator for another namespace?
Could you 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
{
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));
}
source
share