本文整理匯總了PHP中Phalcon\Mvc\Model\Criteria::where方法的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria::where方法的具體用法?PHP Criteria::where怎麽用?PHP Criteria::where使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phalcon\Mvc\Model\Criteria
的用法示例。
在下文中一共展示了Criteria::where方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addCondition
public function addCondition($condition)
{
if ($this->conditionCount == 0) {
$this->query->where($condition);
} else {
$this->query->addWhere($condition);
}
$this->conditionCount += 1;
}
示例2: fromInput
public function fromInput($modelName, $data)
{
if (!is_array($data)) {
throw new Exception("Input data must be an Array");
}
$conditions = array();
if (count($data)) {
$metaData = $this->getDI()->getShared('modelsMetadata');
$model = new $modelName();
$dataTypes = $metaData->getDataTypes($model);
$columnMap = $metaData->getReverseColumnMap($model);
$bind = array();
foreach ($data as $fieldName => $value) {
if (isset($columnMap[$fieldName])) {
$field = $columnMap[$fieldName];
} else {
continue;
}
if (isset($dataTypes[$field])) {
if (!is_null($value)) {
if ($value != '') {
$type = $dataTypes[$field];
if ($type == 2) {
$condition = $fieldName . " LIKE :" . $fieldName . ":";
$bind[$fieldName] = '%' . $value . '%';
} else {
$condition = $fieldName . ' = :' . $fieldName . ':';
$bind[$fieldName] = $value;
}
$conditions[] = $condition;
}
}
}
}
}
$criteria = new Criteria();
if (count($conditions)) {
$joinConditions = join(' AND ', $conditions);
$criteria->where($joinConditions);
$criteria->bind($bind);
}
return $criteria;
}
示例3: fromInput
/**
* Builds a \Phalcon\Mvc\Model\Criteria based on an input array like $_POST
*
* @param \Phalcon\DiInterface $dependencyInjector
* @param string $modelName
* @param array $data
* @return \Phalcon\Mvc\Model\Criteria
* @throws Exception
*/
public static function fromInput($dependencyInjector, $modelName, $data)
{
if (is_object($dependencyInjector) === false || $dependencyInjector instanceof DiInterface === false) {
throw new Exception('A dependency injector container is required to obtain the ORM services');
}
if (is_string($modelName) === false) {
throw new Exception('Invalid parameter type.');
}
if (is_array($data) === false) {
throw new Exception('Model data must be an Array');
}
if (empty($data) === false) {
$conditions = array();
$metaData = $dependencyInjector->getShared('modelsMetadata');
$model = new $modelName();
$dataTypes = $metaData->getDataTypes($model);
$bind = array();
//We look for attributes in the array passed as data
foreach ($data as $field => $value) {
if (isset($dataTypes[$field]) === true && is_null($value) === false && $value !== '') {
if ($dataTypes[$field] === 2) {
//For varchar types we use LIKE operator
$condition = $field . ' LIKE :' . $field . ':';
$bind[$field] = '%' . $value . '%';
} else {
//For the rest of data types we use a plain = operator
$condition = $field . '=:' . $field . ':';
$bind[$field] = $value;
}
$conditions[] = $condition;
}
}
}
//Create an object instance and pass the parameters to it
$criteria = new Criteria();
if (isset($conditions) === true && empty($conditions) === false) {
$criteria->where(implode(' AND ', $conditions));
$criteria->bind($bind);
}
$criteria->setModelName($modelName);
return $criteria;
}