findBy () all records with two conditions

0

I'm trying to work with findBy() on an application made in Symfony2. I would like to put two conditions in FindBy or mix with Where if possible but I am not getting it.

$properties = $em->getRepository('PropertyBundle:Property')->findBy(array(),array('name' => 'ASC'));

I would like to include conditions active = '1' to choose only the records that contain the active (active) status.

$properties = $em->getRepository('CitraxPropertyBundle:Property')->findBy(array(),array('name' => 'ASC'),array('active' => 1));
    
asked by anonymous 11.06.2015 / 15:17

1 answer

3

Here are some examples of the doctrine documentation itself. Doctrine site session 7.8.2. By Simple Conditions site

    <?php
// $em instanceof EntityManager

// All users that are 20 years old
$users = $em->getRepository('MyProject\Domain\User')->findBy(array('age' => 20));

// All users that are 20 years old and have a surname of 'Miller'
$users = $em->getRepository('MyProject\Domain\User')->findBy(array('age' => 20, 'surname' => 'Miller'));

// A single user by its nickname
$user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb'));

The official symfony documentation also has some examples symfony documentation that talks about findby

This example is in the above link

    // query for one product matching by name and price
$product = $repository->findOneBy(
    array('name' => 'foo', 'price' => 19.99)
);

// query for all products matching the name, ordered by price
$products = $repository->findBy(
    array('name' => 'foo'),
    array('price' => 'ASC')
);
    
12.06.2015 / 13:17