PHP code example of artvys / cake-search
1. Go to this page and download the library: Download artvys/cake-search 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/ */
artvys / cake-search example snippets
use App\Model\Entity\Article;
use Artvys\Search\Cake\Engines\Compiled\SearchSources\Table\TableSearchSource;
class ArticlesTableSearchSource extends TableSearchSource {
protected function table(): Table {
return TableRegistry::getTableLocator()->get('Articles');
}
protected function fields(SearchFieldBuilder $builder, CompiledQuery $query, int $limit): void {
$builder->add(Field::contains('title'))
->add(Field::contains('body'));
}
protected function makeResultMapper(): callable {
return fn(Article $a) => SearchResult::make($a->title, $a->body, Router::url(['controller' => 'Articles', 'action' => 'edit']));
}
}