2

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
Victor Bocharsky
  • 11,930
  • 13
  • 58
  • 91
Kev
  • 171
  • 2
  • 19
  • I'd suggest you to use Translatable doctrine extension in pair with jms/i18n-routing-bundle for i18n. – ozahorulia Feb 12 '14 at 10:49
  • I have already make some test with StofDoctrineExtensionsBundle but with this I have another problem. ^^ – Kev Feb 12 '14 at 11:01
  • I just want to say that translatable is really tested and stable extension, which works on a lot of sites... instead of bundles your're trying to implement. – ozahorulia Feb 12 '14 at 11:05
  • You talking about Translatable in StofDoctrineExtensionsBundle or another bundle ? Thanks for you answer. I found Prezent in this post : http://stackoverflow.com/a/19430025/2543271 and he seem to say Gedmo is deprecated. Maybe I miss something. – Kev Feb 12 '14 at 11:21
  • Gemdo is not actively developed any more AFAIK. But you can use `DoctrineBehaviours` from [KnpLabs](https://github.com/KnpLabs/DoctrineBehaviors#translatable). – ferdynator Feb 12 '14 at 12:19
  • Hmm, didn't know that about gedmo... it worked fine for me lately. On the other hand `PrezentBundle` is still beta AFAIK. Besides, last commints on github were 4-8 months ago. Anyway, this is already off-topic a bit :) – ozahorulia Feb 12 '14 at 12:49
  • Thanks for the informations ! If I have too much problem with Prezent I'll change for KNPLabs – Kev Feb 12 '14 at 16:45

1 Answers1

4

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.

ozahorulia
  • 9,798
  • 8
  • 48
  • 72