3.4 Sections

# Class Phalcon\Mvc\Model\Criteria

This class is used 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(["type" => "mechanical"])
->limit(5, 10)
->orderBy("name")
->execute();

``````

## Methods

public setDI (Phalcon\DiInterface \$dependencyInjector)

Sets the DependencyInjector container

public getDI ()

Returns the DependencyInjector container

public setModelName (mixed \$modelName)

Set a model on which the query will be executed

public getModelName ()

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

public bind (array \$bindParams, [mixed \$merge])

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

public bindTypes (array \$bindTypes)

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

public distinct (mixed \$distinct)

Sets SELECT DISTINCT / SELECT ALL flag

 public Phalcon\Mvc\Model\Criteria columns (string array \$columns)

Sets the columns to be queried

``````<?php

\$criteria->columns(
[
"id",
"name",
]
);

``````

public join (mixed \$model, [mixed \$conditions], [mixed \$alias], [mixed \$type])

Adds an 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 innerJoin (mixed \$model, [mixed \$conditions], [mixed \$alias])

Adds an 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");

``````

public leftJoin (mixed \$model, [mixed \$conditions], [mixed \$alias])

Adds a LEFT join to the query

``````<?php

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

``````

public rightJoin (mixed \$model, [mixed \$conditions], [mixed \$alias])

Adds a RIGHT join to the query

``````<?php

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

``````

public where (mixed \$conditions, [mixed \$bindParams], [mixed \$bindTypes])

Sets the conditions parameter in the criteria

public addWhere (mixed \$conditions, [mixed \$bindParams], [mixed \$bindTypes])

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

public andWhere (mixed \$conditions, [mixed \$bindParams], [mixed \$bindTypes])

Appends a condition to the current conditions using an AND operator

public orWhere (mixed \$conditions, [mixed \$bindParams], [mixed \$bindTypes])

Appends a condition to the current conditions using an OR operator

public betweenWhere (mixed \$expr, mixed \$minimum, mixed \$maximum)

Appends a BETWEEN condition to the current conditions

``````<?php

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

``````

public notBetweenWhere (mixed \$expr, mixed \$minimum, mixed \$maximum)

Appends a NOT BETWEEN condition to the current conditions

``````<?php

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

``````

public inWhere (mixed \$expr, array \$values)

Appends an IN condition to the current conditions

``````<?php

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

``````

public notInWhere (mixed \$expr, array \$values)

Appends a NOT IN condition to the current conditions

``````<?php

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

``````

public conditions (mixed \$conditions)

Adds the conditions parameter to the criteria

public order (mixed \$orderColumns)

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

public orderBy (mixed \$orderColumns)

Adds the order-by clause to the criteria

public groupBy (mixed \$group)

Adds the group-by clause to the criteria

public having (mixed \$having)

Adds the having clause to the criteria

public limit (mixed \$limit, [mixed \$offset])

Adds the limit parameter to the criteria.

``````<?php

\$criteria->limit(100);
\$criteria->limit(100, 200);
\$criteria->limit("100", "200");

``````

public forUpdate ([mixed \$forUpdate])

Adds the “for_update” parameter to the criteria

public sharedLock ([mixed \$sharedLock])

Adds the “shared_lock” parameter to the criteria

public cache (array \$cache)

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

public getWhere ()

Returns the conditions parameter in the criteria

 public string array null getColumns ()

Returns the columns to be queried

public getConditions ()

Returns the conditions parameter in the criteria

 public int array null getLimit ()

Returns the limit parameter in the criteria, which will be an integer if limit was set without an offset, an array with ‘number’ and ‘offset’ keys if an offset was set with the limit, or null if limit has not been set.

public getOrderBy ()

Returns the order clause in the criteria

public getGroupBy ()

Returns the group clause in the criteria

public getHaving ()

Returns the having clause in the criteria

public array getParams ()

Returns all the parameters defined in the criteria

public static fromInput (Phalcon\DiInterface \$dependencyInjector, mixed \$modelName, array \$data, [mixed \$operator])

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

public createBuilder ()

Creates a query builder from criteria.

``````<?php

\$builder = Robots::query()
->where("type = :type:")
->bind(["type" => "mechanical"])
->createBuilder();

``````

public execute ()

Executes a find using the parameters built with the criteria
{"ft_lang_label":"__label__en","ft_lang_prob":0.5284031,"math_prob":0.7591644,"size":5426,"snap":"2019-13-2019-22","text_gpt3_token_len":1310,"char_repetition_ratio":0.2167097,"word_repetition_ratio":0.19424461,"special_character_ratio":0.24769628,"punctuation_ratio":0.14253135,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9781953,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-05-21T13:43:01Z\",\"WARC-Record-ID\":\"<urn:uuid:a8ad8c4d-ef92-448a-b119-3b2967250ad3>\",\"Content-Length\":\"79499\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:26d44408-5769-4f65-94e0-13997c1cc02c>\",\"WARC-Concurrent-To\":\"<urn:uuid:afcd9dab-171b-43a3-af45-b09740f0f57f>\",\"WARC-IP-Address\":\"104.18.35.141\",\"WARC-Target-URI\":\"https://docs.phalconphp.com/3.4/de-de/api/Phalcon_Mvc_Model_Criteria\",\"WARC-Payload-Digest\":\"sha1:PDAI2LHFC6PJJMRGRKST554ZVFRJQWMZ\",\"WARC-Block-Digest\":\"sha1:6P2UW5TZ7PO3AMB3ELQAD2AFWOC6DFIO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-22/CC-MAIN-2019-22_segments_1558232256381.7_warc_CC-MAIN-20190521122503-20190521144503-00087.warc.gz\"}"}