Some examples of Propel Criteria syntax

To start, we have a Criteria, with a Criterion for each condition :

$criteria = new Criteria();

$a = $criteria->getNewCriterion( /* A */ );
$b = $criteria->getNewCriterion( /* B */ );
$c = $criteria->getNewCriterion( /* C */ );
...

A AND B

$a->addAnd($b);

A AND (B OR C)

$b->addOr($c);
$a->addAnd($b);

(A AND B) OR (C AND D)

$a->addAnd($b);
$c->addAnd($d);
$a->addOr($c);

A AND (B OR (C AND D))

$c->addAnd($d);
$b->addOr($c);
$a->addAnd($b);

And, don't forget to link your main Criteria with your first condition ($a in these examples) :

$criteria->add($a);

You can generate more complicated cases with the Propel Criteria Builder.

If you use Propel 1.5 (or newer), you can avoid using criterias, check Propel Documantation to learn more. Get more advanced examples on Propel 1.5 lead developer's blog.

post a comment