Open Source Content Management Framework

MidgardQueryBuilder method add_placeholder_constraint

  1. Usage:

This method has been implemented for Query Builder after Midgard 1.7.0 release.

void $qb->add_placeholder_constraint(str property, str constraint)

add_placeholder_constraint is like the add_constraint method in that it adds a query constraint to a Query Builder. The difference is that the add_placeholder_constraint method makes it possible to delay the setting of the constraint value to when the query is executed.

The method takes two arguments:

  • property is the name of a property in the MgdSchema type the constraint applies for
  • constraint is the comparison used for the constraint.

See the add_constraint method for the argument details.

The values of the placeholder constraints are set when the query is executed. The argument array passed to the execute or count method should contain as many elements as there are placeholder constraints. The argument values are then used as the placeholder constraint values while the query is being executed.

Usage:

<?php
$qb = new MidgardQueryBuilder("midgard_article");
$qb->add_placeholder_constraint('topic', '=');

// List articles from topic 1
$qb->execute(array(1));

// List articles from topic 2
$qb->execute(array(2));

// Count articles from topic 3
$qb->count(array(3));
?>

MidgardQueryBuilder class name is deprecated since Midgard 1.8. Use midgard_query_builder class name. Deprecated name will be removed in Midgard 2.0

Designed by Nemein, hosted by Anykey