I am trying to run sql query. I am trying to select users with specific roles. Below my query:
$roleUser= $this->container->getParameter('user_role');
$query = $this->getDoctrine()->getEntityManager()
->createQuery(
'SELECT u FROM UserBundle:User ur
WHERE ur.role IN :role_user')
->setParameters('role_user',$roleUser);
In my config.yml I defined my user roles
parameters:
user_role:
- ADMIN1
- ADMIN2
- ADMIN3
I want to select all the user that has one of the role ADMIN1, ADMIN2 or ADMIN3.
Here is the error message:
Warning: Invalid argument supplied for foreach() in /Test/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php line 246
{
$types = array();
foreach ($this->parameters as $parameter) {
/** @var Query\Parameter $parameter */
$types[$parameter->getName()] = $parameter->getType();
}
Try with setParameter
instead of setParameters
:
try this:
->setParameter('role_user',$roleUser);
instead of this:
->setParameters('role_user',$roleUser);
More info about setting parameters here in the doc.
Hope this help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With