PHP code example of heyday / silverstripe-querybuilder

1. Go to this page and download the library: Download heyday/silverstripe-querybuilder 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/ */

    

heyday / silverstripe-querybuilder example snippets


use Heyday\QueryBuilder\Interfaces\QueryBuilderInterface;
use Heyday\QueryBuilder\Interfaces\QueryModifierInterface;

class LikeModifier extends QueryModifierInterface
{
	protected $column;
	public function __construct($column)
	{
		$this->column = $column;
	}
	public function modify(\SQLQuery $query, array $data, QueryBuilderInterface $queryBuilder)
	{
		if (isset($data['search']) && $data['search']) {
			$query->addWhere("{$this->column} LIKE '%{$data['search']}%'");
		}
	}
}

use Heyday\QueryBuilder\QueryBuilder;

$qb = new QueryBuilder(
	'SiteTree',
	[new LikeModifier('SiteTree.Title')],
	['search' => $request->getVar('q')]
);

foreach ($qb as $page) {
	// Do something with page
}