Download the PHP package xcartmansft/suggest-bundle without Composer
On this page you can find all versions of the php package xcartmansft/suggest-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xcartmansft/suggest-bundle
More information about xcartmansft/suggest-bundle
Files in xcartmansft/suggest-bundle
Package suggest-bundle
Short Description symfony2 suggest (autocomplete) bundle
License MIT
Informations about the package suggest-bundle
SuggestBundle
About
This is a Symfony bundle which enables the popular Select2 component to be used as a drop-in replacement for a standard entity, document and choice fields on a Symfony form.
The main feature of this bundle is that the list of choices is retrieved via a remote ajax call.
1. Installation
Add the sirian/suggest-bundle package to your require section in the composer.json file.
Add the SuggestBundle to your application's kernel:
2. Configuration
After installing the bundle, make sure you add this route to your routing:
And choose default widget for form (depends on select2 version you use). One of select2_v3, select2_v4. You could also specify other default form options for SuggestType::class
3. Configuring suggesters
3.1. Doctrine ODM Document suggesters
3.2. Doctrine ORM Entity suggesters
3.3. Custom suggesters
When you need some additional logic - you could create your own suggester. For example let's create AdminSuggester which suggests only users having ROLE_ADMIN role
Define service services.yml with sirian_suggest.suggester tag
Alias admin will be used in suggester option for SuggestType::class and in /suggest/admin url pattern.
4. Using
Now you can use configured suggesters in forms
5. Security
You could restrict access to suggesters by securing URL patterns
6. Passing additional options to suggester
Sometimes you need to pass additional parameters to Suggester.
6.1. Static extra options
Let's start with simple example. You have brands and models and you want to display only models for one specific brand.
Create class ModelSuggester
Define service
and add extra option to form options:
6.2. Dynamic extra options
Now let's see an example when you have 2 suggest fields brand and model and in second select you want to display models for selected brand.
You need to create ModelSuggester and define suggester service (like in previous section).
And then customize form widget to pass brand_id extra option to suggester