expressions.rst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Expressions
  2. ===========
  3. The ``Doctrine\Common\Collections\Expr\Comparison`` class
  4. can be used to create expressions to be used with the
  5. ``Doctrine\Common\Collections\Criteria`` class. It has the
  6. following operator constants:
  7. - ``Comparison::EQ``
  8. - ``Comparison::NEQ``
  9. - ``Comparison::LT``
  10. - ``Comparison::LTE``
  11. - ``Comparison::GT``
  12. - ``Comparison::GTE``
  13. - ``Comparison::IS``
  14. - ``Comparison::IN``
  15. - ``Comparison::NIN``
  16. - ``Comparison::CONTAINS``
  17. - ``Comparison::MEMBER_OF``
  18. - ``Comparison::STARTS_WITH``
  19. - ``Comparison::ENDS_WITH``
  20. The ``Doctrine\Common\Collections\Criteria`` class has the following
  21. API to be used with expressions:
  22. where
  23. -----
  24. Sets the where expression to evaluate when this Criteria is searched for.
  25. .. code-block:: php
  26. $expr = new Comparison('key', Comparison::EQ, 'value');
  27. $criteria->where($expr);
  28. andWhere
  29. --------
  30. Appends the where expression to evaluate when this Criteria is searched for
  31. using an AND with previous expression.
  32. .. code-block:: php
  33. $expr = new Comparison('key', Comparison::EQ, 'value');
  34. $criteria->andWhere($expr);
  35. orWhere
  36. -------
  37. Appends the where expression to evaluate when this Criteria is searched for
  38. using an OR with previous expression.
  39. .. code-block:: php
  40. $expr1 = new Comparison('key', Comparison::EQ, 'value1');
  41. $expr2 = new Comparison('key', Comparison::EQ, 'value2');
  42. $criteria->where($expr1);
  43. $criteria->orWhere($expr2);
  44. orderBy
  45. -------
  46. Sets the ordering of the result of this Criteria.
  47. .. code-block:: php
  48. $criteria->orderBy(['name' => Criteria::ASC]);
  49. setFirstResult
  50. --------------
  51. Set the number of first result that this Criteria should return.
  52. .. code-block:: php
  53. $criteria->setFirstResult(0);
  54. getFirstResult
  55. --------------
  56. Gets the current first result option of this Criteria.
  57. .. code-block:: php
  58. $criteria->setFirstResult(10);
  59. echo $criteria->getFirstResult(); // 10
  60. setMaxResults
  61. -------------
  62. Sets the max results that this Criteria should return.
  63. .. code-block:: php
  64. $criteria->setMaxResults(20);
  65. getMaxResults
  66. -------------
  67. Gets the current max results option of this Criteria.
  68. .. code-block:: php
  69. $criteria->setMaxResults(20);
  70. echo $criteria->getMaxResults(); // 20