Question

I want create a multilingual web site, and for that I use Symfony with the PrezentBundle and A2lixBundle. I would get the list of my data by locale with entity repo.

I have this error :

FatalErrorException: Error: __clone method called on non-object in /project/vendor/doctrine/orm/lib/Doctrine/ORM/QueryBuilder.php line 238

Here is my repo :

$qb = $this->createQueryBuilder('c')
        ->leftJoin('c.criteres', 'crit')
        ->leftjoin('c.translations', 'ct', 'WITH', 'ct.locale = :locale')
        ->setParameters('locale', 'fr');
var_dump($qb->getDql() );

return $qb->getQuery()
        ->getResult();

The var_dump give me that :

SELECT c FROM NS\MyBundle\Entity\CritereCateg c LEFT JOIN c.criteres crit LEFT JOIN c.translations ct WITH ct.locale = :locale
Was it helpful?

Solution

Your issue is probably because of misuse of the setParameters() mehtod. There is two simmilar methods for the doctrine query builder:

1) setParameter() which sets only one parameter per method usage. The syntax is:

// for numeric parameters
$qb->leftjoin('c.translations', 'ct', 'WITH', 'ct.locale = ?1')
   ->setParameter(1, 'fr');

// for string parameters
$qb->leftjoin('c.translations', 'ct', 'WITH', 'ct.locale = :locale')
   ->setParameter('locale', 'fr');

2) setParameters() which sets multiple parameters:

// String params
$qb->where('u.id = :uid')
   ->leftjoin('c.translations', 'ct', 'WITH', 'ct.locale = :locale')
   ->setParameters(array('locale' => 'fr', 'uid' => $userId));

// Numeric parameters are also available here
$qb->where('u.id = ?1')
   ->leftjoin('c.translations', 'ct', 'WITH', 'ct.locale = ?2')
   ->setParameters(array(2 => 'fr', 1 => $userId));

So you probably wanted to use setParameter() instead of setParameters() in your query builder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top