PHP code example of antqa / ajax-autocomplete-bundle
1. Go to this page and download the library: Download antqa/ajax-autocomplete-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/ */
antqa / ajax-autocomplete-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new AntQa\AjaxAutoCompleteBundle\AntQaAjaxAutoCompleteBundle(),
);
}
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\ORM\Query\Expr;
public function findAction(Request $request)
{
$expr = new Expr();
$objects = $this->getManager()
->getRepository('Acme:Object')
->createQueryBuilder('o')
->select('o.name, o.id')
->where($expr->like('o.name', ':name'))
->setParameter('name', sprintf('%s%%', $request->query->get('q', '')))
->getQuery()
->getArrayResult();
return new JsonResponse($objects);
}
public function get($ids)
{
$expr = new Expr();
$ids = explode(',', $ids);
$objects = $this->getManager()
->getRepository('Acme:Object')
->createQueryBuilder('o')
->select('o.id, o.name')
->where($expr->in('o.id', ':ids'))
->setParameter('ids', $ids)
->getQuery()
->getArrayResult();
return new JsonResponse($objects);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.