1. Go to this page and download the library: Download zenbox/doctrine 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/ */
zenbox / doctrine example snippets
$qb = $this->createQueryBuilder('a');
$qb->orderBy('a.date','DESC');
$collection = new QueryBuilderCollection($qb);
$collection->count(); // returns the total number of records
$collection->slice(0, 10); // request limited 10 records from the database
use Doctrine\Common\Collections\ArrayCollection;
$dataProvider = new DataProvider(new ArrayCollection([...]));
// iterable
foreach ($dataProvider as $object) {
// do something
}
$array = $dataProvider->toArray(); // returns 20 records
use ZenBox\Doctrine\Extractor\ExtractorInterface;
// implement extractor
class UserExtractor implements ExtractorInterface
{
public function extract(object $object) : array
{
// TODO: Implement extract() method.
}
}
// fetch collection from repository
$collection = $repository->findAll();
$dataProvider = new DataProvider($collection, new UserExtractor());
// iterable
foreach ($dataProvider as $row) {
// do something
}
$array = $dataProvider->extract(); // returns 20 rows