Documentation

Table Of Contents

Previous topic

< Class Phalcon\Mvc\Model\Behavior\Timestampable

Next topic

Class Phalcon\Mvc\Model\Exception >

This Page

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

<?php

$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\Criteria 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\Criteria bind (string $bindParams)

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

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

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

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

Sets the columns to be queried

<?php

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

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

Adds a INNER join to the query

<?php

$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\Query\Builder innerJoin (string $model, [string $conditions], [string $alias])

Adds a INNER join to the query

<?php

$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\Query\Builder leftJoin (string $model, [string $conditions], [string $alias])

Adds a LEFT join to the query

<?php

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

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

Adds a RIGHT join to the query

<?php

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

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

Sets the conditions parameter in the criteria

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

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

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

Appends a condition to the current conditions using an AND operator

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

Appends a condition to the current conditions using an OR operator

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

Appends a BETWEEN condition to the current conditions

<?php

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

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

Appends a NOT BETWEEN condition to the current conditions

<?php

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

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

Appends an IN condition to the current conditions

<?php

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

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

Appends a NOT IN condition to the current conditions

<?php

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

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

Adds the conditions parameter to the criteria

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

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

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

Adds the order-by parameter to the criteria

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

Adds the limit parameter to the criteria

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

Adds the “for_update” parameter to the criteria

public Phalcon\Mvc\Model\Criteria 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 string getParams ()

Returns all the parameters defined in the criteria

public static static 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