lio89
lio89

Reputation: 115

Symfony unexplainable foreach error, without having any foreach

None of the suggested questions apply for this case, because I don't have any foreach in my code but the error code keep saying that..

My action is:

public function doctrinoAction()
    {
        $id=1;
        $em = $this->getDoctrine()->getManager();
        $dql = 'SELECT p FROM TPMainBundle:Works p WHERE p.id = :id';
        $consulta = $em->createQuery($dql)->setParameters('id', $id);
        $productos = $consulta->getResult();
        return $this->render('TPMainBundle:Default:indra.html.php', array(
                    'productos' => $productos,
        ));
    }

And my View is just:

<?php
echo 'lio';

NO foreach. I could write anything in the view, and the error code will be the same. I could send the render to any view that it doesn't reach it, the error code is:

ContextErrorException: Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\TP\vendor\doctrine\orm\lib\Doctrine\ORM\Query.php line 303 

And I'm working in dev, and cleared the cache.. What is happening?

The only existing 'foreach' loop, is the one located at that "Query.php" file, but It's not created by me.

Line 303 of query.php:

foreach ($this->parameters as $parameter) {
        $key    = $parameter->getName();
        $value  = $parameter->getValue();

Please help

Upvotes: 1

Views: 725

Answers (1)

Berriel
Berriel

Reputation: 13611

Try to change

$consulta = $em->createQuery($dql)->setParameters('id', $id);

To this:

$consulta = $em->createQuery($dql)->setParameter('id', $id);

Or to this:

$params = array('id' => $id);
$consulta = $em->createQuery($dql)->setParameters($params);

Upvotes: 2

Related Questions