0

I have a simple controller as following:

public function fetchDataAction($username){
    $user_email = $this -> getDoctrine()
        -> getRepository('AdminBundle:Users')
        -> findBy( array('username' => $username ), array('id' => 2));

    return $this -> render('AdminBundle:Admin:fetchData.html.twig', array('datas' => $user_email));
}

But in running the code I face the error:

Invalid order by orientation specified for AdminBundle\Entity\Users#userId

Passing one array to findBy() method, the code run errorlessly, But When I pass multiple arrays, It fails!

Where is the problem?

2
  • 1
    What exactly do you want to achieve? Commented May 29, 2017 at 8:49
  • I want to append records that satisfy one of my conditions (OR operator) not all of my condition Commented May 29, 2017 at 9:26

1 Answer 1

2

Problem is that second parameter to findBy is sort order. Passing array('id' => 2) as a sort order causes your error (if you've read it's text).

So the solution is to pass both filter criterias in one array:

-> findBy( array('username' => $username, 'id' => 2) );
Sign up to request clarification or add additional context in comments.

3 Comments

I want records having username = $username OR records having id = 2. I think your recommendation give those records have username = $username AND records having id = 2. Am I right?
Yes, you're right. In your case it is stackoverflow.com/questions/34003492/…
Thanks but links didn't help! You know I do according to Symfony document symfony.com/doc/current/… but the result is not desirable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.