1. Go to this page and download the library: Download sirian/suggest-bundle 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/ */
sirian / suggest-bundle example snippets
namespace App\MainBundle\Suggest;
use App\MainBundle\Document\User;
use Doctrine\Common\Persistence\ManagerRegistry;
use Sirian\SuggestBundle\Suggest\DocumentSuggester;
use Sirian\SuggestBundle\Suggest\Item;
use Sirian\SuggestBundle\Suggest\SuggestQuery;
class AdminSuggester extends DocumentSuggester
{
public function __construct(ManagerRegistry $registry)
{
$options = [
'class' => User::class,
'id_property' => 'id',
'property' => 'username',
'search' => [
'name' => DocumentSuggester::SEARCH_MIDDLE,
'username' => DocumentSuggester::SEARCH_MIDDLE,
'email' => DocumentSuggester::SEARCH_MIDDLE
]
];
parent::__construct($registry, $options);
}
protected function createSuggestQueryBuilder(SuggestQuery $query)
{
$qb = parent::createSuggestQueryBuilder($query);
$qb->field('roles')->equals('ROLE_ADMIN');
return $qb;
}
protected function transformObject($user)
{
$item = new Item();
$item->id = $user->getId();
$item->text = $user->getName() . ' ( ' . $user->getUsername() . ', ' . $user->getEmail() . ')';
return $item;
}
}