本文整理汇总了PHP中TCriteria::dump方法的典型用法代码示例。如果您正苦于以下问题:PHP TCriteria::dump方法的具体用法?PHP TCriteria::dump怎么用?PHP TCriteria::dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCriteria
的用法示例。
在下文中一共展示了TCriteria::dump方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: TCriteria
$criteria = new TCriteria();
$criteria->add(new TFilter('telefone', 'IS NOT', NULL));
$criteria->add(new TFilter('sexo', '=', 'F'));
echo $criteria->dump();
echo " <br>\n";
// aqui vemos o uso dos operadores de comparação IN e NOT IN juntamente com
// conjuntos de strings. Neste caso, a UF deve estar entre (RS, SC e PR) E
// não deve estar entre (AC e PI).
$criteria = new TCriteria();
$criteria->add(new TFilter('UF', 'IN', array('RS', 'SC', 'PR')));
$criteria->add(new TFilter('UF', 'NOT IN', array('AC', 'PI')));
echo $criteria->dump();
echo " <br>\n";
// neste caso temos o uso de um critério composto
// o primeiro critério aponta para sexo='F'
// (sexo feminino) e idade > 18 (maior de idade)
$criteria1 = new TCriteria();
$criteria1->add(new TFilter('sexo', '= ', 'F'));
$criteria1->add(new TFilter('idade', '>', '18'));
// o segundo critério aponta para sexo=M (masculino)
// e idade < 16 (menor de idade)
$criteria2 = new TCriteria();
$criteria2->add(new TFilter('sexo', '= ', 'M'));
$criteria2->add(new TFilter('idade', '<', '16'));
// agora juntamos os dois critérios utilizando o operador lógico OR (ou). O resultado
// deve conter "mulheres maiores de 18" OU "homens menores de 16"
$criteria = new TCriteria();
$criteria->add($criteria1, TExpression::OR_OPERATOR);
$criteria->add($criteria2, TExpression::OR_OPERATOR);
echo $criteria->dump();
echo " <br>\n";
示例2: __construct
public function __construct()
{
parent::__construct();
try {
/**
* Creates a criteria where the age is
* less than 16 OR the age is greater than 60
*/
$criteria = new TCriteria();
$criteria->add(new TFilter('age', '<', 16), TExpression::OR_OPERATOR);
$criteria->add(new TFilter('age', '>', 60), TExpression::OR_OPERATOR);
echo $criteria->dump();
echo "<br>\n";
/**
* Creates a criteria where the age is
* less than 16 OR the age is greater than 60
*/
$criteria = new TCriteria();
$criteria->add(new TFilter('age', 'BETWEEN', 16, 60));
echo $criteria->dump();
echo "<br>\n";
/**
* Creates a criteria where the age is IN a (24,25,26)
* and the age is not in (10)
*/
$criteria = new TCriteria();
$criteria->add(new TFilter('age', 'IN', array(24, 25, 26)));
$criteria->add(new TFilter('age', 'NOT IN', array(10)));
echo $criteria->dump();
echo "<br>\n";
/**
* Creates a criteria where name start with pedro
* OR name start with maria
*/
$criteria = new TCriteria();
$criteria->add(new TFilter('nome', 'like', 'pedro%'), TExpression::OR_OPERATOR);
$criteria->add(new TFilter('nome', 'like', 'maria%'), TExpression::OR_OPERATOR);
echo $criteria->dump();
echo "<br>\n";
/**
* Creates a criteria where cellphone is not NULL
* AND genre is FEMALE
*/
$criteria = new TCriteria();
$criteria->add(new TFilter('cellphone', 'IS NOT', NULL));
$criteria->add(new TFilter('gender', '=', 'F'));
echo $criteria->dump();
echo "<br>\n";
/**
* Creates a criteria where state is IN the set ('RS', 'SC', 'PR')
* AND state NOT IN array('AC', 'PI')
*/
$criteria = new TCriteria();
$criteria->add(new TFilter('state', 'IN', array('RS', 'SC', 'PR')));
$criteria->add(new TFilter('state', 'NOT IN', array('AC', 'PI')));
echo $criteria->dump();
echo "<br>\n";
$criteria = new TCriteria();
$criteria->add(new TFilter('id', 'IN', '(SELECT customer_id FROM purchases)'));
echo $criteria->dump();
// (id IN (SELECT customer_id FROM purchases))
echo "<br>\n";
$criteria = new TCriteria();
$criteria->add(new TFilter('birthdate', '<=', "NOESC:date(now()) - '2 years'::interval"));
echo $criteria->dump();
// (birthdate <= date(now()) - '2 years'::interval)
echo "<br>\n";
/**
* Creates a criteria where the gender is Female
* and age is greater than 18
*/
$criteria1 = new TCriteria();
$criteria1->add(new TFilter('gender', '= ', 'F'));
$criteria1->add(new TFilter('age', '>', '18'));
/*
* Creates a criteria where the gender is Male
* and age is less than 16
*/
$criteria2 = new TCriteria();
$criteria2->add(new TFilter('gender', '= ', 'M'));
$criteria2->add(new TFilter('age', '<', '16'));
/**
* Creates a criteria that combines the two previous
* criterias with the OR operator.
*/
$criteria = new TCriteria();
$criteria->add($criteria1, TExpression::OR_OPERATOR);
$criteria->add($criteria2, TExpression::OR_OPERATOR);
echo $criteria->dump();
echo "<br>\n";
} catch (Exception $e) {
new TMessage('error', $e->getMessage());
}
}