PHP code example of bipiane / criteria-builder
1. Go to this page and download the library: Download bipiane/criteria-builder library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bipiane / criteria-builder example snippets
/**
* GET ../api/users?
* limit=12&
* offset=1&
* sort=city-name&
* order=ASC&
* lastname[like]=Pian%&
* city-state-code[ne]=null&
* city-state-country=1&
* enabled=true&
* id[ge]=50
* @param Request $request
*/
public function exampleAction(Request $request)
{
$criteriaUser = [
'id' => CriteriaDoctrine::CRITERIAS_NUMBER,
'name' => CriteriaDoctrine::CRITERIAS_STRING,
'lastname' => CriteriaDoctrine::CRITERIAS_STRING,
'city' => [
'id' => CriteriaDoctrine::CRITERIAS_NUMBER,
'name' => CriteriaDoctrine::CRITERIAS_STRING,
'state' => [
'id' => CriteriaDoctrine::CRITERIAS_NUMBER,
'name' => CriteriaDoctrine::CRITERIAS_STRING,
'code' => CriteriaDoctrine::CRITERIAS_STRING,
'country' => [
'id' => CriteriaDoctrine::CRITERIAS_NUMBER,
'name' => CriteriaDoctrine::CRITERIAS_STRING,
'enabled' => CriteriaDoctrine::CRITERIAS_BOOLEAN,
],
'enabled' => CriteriaDoctrine::CRITERIAS_BOOLEAN,
],
'enabled' => CriteriaDoctrine::CRITERIAS_BOOLEAN,
],
'enabled' => CriteriaDoctrine::CRITERIAS_BOOLEAN,
];
try {
$qb = $this->getDoctrine()->getManager()
->getRepository('ModelBundle:User')
->createQueryBuilder('usr');
$qb = CriteriaBuilder::fetchFromQuery(
$qb,
$request->query->all(),
$criteriaUser
);
var_dump($qb->getQuery()->getArrayResult());
} catch (CriteriaException $e) {
}
// ...
}