This question is placed in the English version of stackoverflow:
link
After several questions I could have the answer I needed, on the same generate a summary, I hope you serve: link
Use symfony 3.3.x. In this way, solve the problem
Service.yml file:
//service.yml
services:
app.queriesmanager:
class: AppBundle\Services\QueriesManager
autowire: true
AppBundle \ Services \ QueriesManager.php file
//AppBundle\Services\QueriesManager.php
<?php
namespace AppBundle\Services;
use Doctrine\ORM\EntityManagerInterface;
class QueriesManager {
protected $entityManager;
public function __construct(EntityManagerInterface $entityManager) {
$this->entityManager = $entityManager;
}
public function searchAdvance($var,$var1,$var2,$var3)
{
$dql1 = "";
$dql2 = "";
$dql = "SELECT pl
FROM BackendBundle:Products p
JOIN BackendBundle:Pricelist pl
WITH p.peachitemid = pl.peachitemid
WHERE p.hasimages = 1
AND p.active = 'FALSE'
AND p.imagesamazon1 = 1
AND p.imagesamazon2 = 1
AND (p.descriptionforsales like '%$var%' OR p.itemid like '%$var%')";
if ($var1 != "select") {
$dql1 = " AND p.newcategory='$var1' AND p.newsubcategory='$var2' ";
}
if ($var3 == "150") {
$dql2 = " AND pl.retail < 150";
}
if ($var3 == "200") {
$dql2 = " AND pl.retail > 150 AND pl.retail < 250 ";
}
if ($var3 == "250") {
$dql2 = " AND pl.retail > 250 ";
}
$dql1 .= $dql2;
$dql .= $dql1;
$query=$this->entityManager->createQuery($dql);
$query = $query->getResult();
return $query;
}
}
DefaultController.php file
//Use the service in controller
$query=$this->get('app.queriesmanager')->searchAdvance($var,$var1,$var2,$var3);
I hope I can help you.