W3cubDocs

/Phalcon 2

Class Phalcon\Mvc\Model\Criteria

implements Phalcon\Mvc\Model\CriteriaInterface, Phalcon\DI\InjectionAwareInterface

This class allows to build the array parameter required by Phalcon\Mvc\Model::find and Phalcon\Mvc\Model::findFirst using an object-oriented interface

$robots = Robots::query()
    ->where("type = :type:")
    ->andWhere("year < 2000")
    ->bind(array("type" => "mechanical"))
    ->order("name")
    ->execute();

Methods

public setDI (Phalcon\DiInterface $dependencyInjector)

Sets the DependencyInjector container

public Phalcon\DiInterface getDI ()

Returns the DependencyInjector container

public Phalcon\Mvc\Model\CriteriaInterface setModelName (string $modelName)

Set a model on which the query will be executed

public string getModelName ()

Returns an internal model name on which the criteria will be applied

public Phalcon\Mvc\Model\CriteriaInterface bind (string $bindParams)

Sets the bound parameters in the criteria This method replaces all previously set bound parameters

public Phalcon\Mvc\Model\CriteriaInterface bindTypes (string $bindTypes)

Sets the bind types in the criteria This method replaces all previously set bound parameters

public Phalcon\Mvc\Model\CriteriaInterface columns (string|array $columns)

Sets the columns to be queried

$criteria->columns(array('id', 'name'));

public Phalcon\Mvc\Model\CriteriaInterface join (string $model, [string $conditions], [string $alias], [string $type])

Adds a join to the query

$criteria->join('Robots');
$criteria->join('Robots', 'r.id = RobotsParts.robots_id');
$criteria->join('Robots', 'r.id = RobotsParts.robots_id', 'r');
$criteria->join('Robots', 'r.id = RobotsParts.robots_id', 'r', 'LEFT');

public Phalcon\Mvc\Model\CriteriaInterface innerJoin (string $model, [string $conditions], [string $alias])

Adds a INNER join to the query

$criteria->innerJoin('Robots');
$criteria->innerJoin('Robots', 'r.id = RobotsParts.robots_id');
$criteria->innerJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
$criteria->innerJoin('Robots', 'r.id = RobotsParts.robots_id', 'r', 'LEFT');

public Phalcon\Mvc\Model\CriteriaInterface leftJoin (string $model, [string $conditions], [string $alias])

Adds a LEFT join to the query

$criteria->leftJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');

public Phalcon\Mvc\Model\CriteriaInterface rightJoin (string $model, [string $conditions], [string $alias])

Adds a RIGHT join to the query

$criteria->rightJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');

public Phalcon\Mvc\Model\CriteriaInterface where (string $conditions)

Sets the conditions parameter in the criteria

public Phalcon\Mvc\Model\CriteriaInterface addWhere (string $conditions, [array $bindParams], [array $bindTypes])

Appends a condition to the current conditions using an AND operator (deprecated)

public Phalcon\Mvc\Model\CriteriaInterface andWhere (string $conditions, [array $bindParams], [array $bindTypes])

Appends a condition to the current conditions using an AND operator

public Phalcon\Mvc\Model\CriteriaInterface orWhere (string $conditions, [array $bindParams], [array $bindTypes])

Appends a condition to the current conditions using an OR operator

public Phalcon\Mvc\Model\CriteriaInterface betweenWhere (string $expr, mixed $minimum, mixed $maximum)

Appends a BETWEEN condition to the current conditions

$criteria->betweenWhere('price', 100.25, 200.50);

public Phalcon\Mvc\Model\CriteriaInterface notBetweenWhere (string $expr, mixed $minimum, mixed $maximum)

Appends a NOT BETWEEN condition to the current conditions

$criteria->notBetweenWhere('price', 100.25, 200.50);

public Phalcon\Mvc\Model\CriteriaInterface inWhere (string $expr, array $values)

Appends an IN condition to the current conditions

$criteria->inWhere('id', [1, 2, 3]);

public Phalcon\Mvc\Model\CriteriaInterface notInWhere (string $expr, array $values)

Appends a NOT IN condition to the current conditions

$criteria->notInWhere('id', [1, 2, 3]);

public Phalcon\Mvc\Model\CriteriaIntreface conditions (string $conditions)

Adds the conditions parameter to the criteria

public Phalcon\Mvc\Model\CriteriaInterface order (string $orderColumns)

Adds the order-by parameter to the criteria (deprecated)

public Phalcon\Mvc\Model\CriteriaInterface orderBy (string $orderColumns)

Adds the order-by parameter to the criteria

public Phalcon\Mvc\Model\CriteriaInterface limit (int $limit, [int $offset])

Adds the limit parameter to the criteria

public Phalcon\Mvc\Model\CriteriaInterface forUpdate ([boolean $forUpdate])

Adds the “for_update” parameter to the criteria

public Phalcon\Mvc\Model\CriteriaInterface sharedLock ([boolean $sharedLock])

Adds the “shared_lock” parameter to the criteria

public string getWhere ()

Returns the conditions parameter in the criteria

public string|array getColumns ()

Return the columns to be queried

public string getConditions ()

Returns the conditions parameter in the criteria

public string getLimit ()

Returns the limit parameter in the criteria

public string getOrder ()

Returns the order parameter in the criteria

public array getParams ()

Returns all the parameters defined in the criteria

public static Phalcon\Mvc\Model\Criteria fromInput (Phalcon\DiInterface $dependencyInjector, string $modelName, array $data)

Builds a Phalcon\Mvc\Model\Criteria based on an input array like $_POST

public Phalcon\Mvc\Model\ResultsetInterface execute ()

Executes a find using the parameters built with the criteria

public Phalcon\Mvc\Model\CriteriaInterface cache (unknown $option)

Sets the cache options in the criteria This method replaces all previously set cache options

© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/2.0.0/api/Phalcon_Mvc_Model_Criteria.html