Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
composer require cmrweb/address-bundleOpen a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require cmrweb/address-bundleThen, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php file of your project:
return [
Cmrweb\AddressBundle\AddressBundle::class => ['all' => true],
];.env
###> cmrweb/address-bundle ###
API_ADDRESS="https://data.geopf.fr/"
###< cmrweb/address-bundle ###config/services.yaml
parameters:
# ...
cmrweb.api.address: '%env(API_ADDRESS)%'
services:
# ...
Cmrweb\AddressBundle\Service\ApiAddressService:
arguments:
$url: '%cmrweb.api.address%'Make Symfony live-component
symfony console make:twig-component --liveUse SearchAddressTrait in your component
// ...
use DefaultActionTrait;
use SearchAddressTrait;Edit your component.html.twig
<!-- without css -->
<div {{attributes}} data-loading="addClass(opacity-80) addAttribute(disabled)">
<input type="text" placeholder="address" autocomplete="false" spellcheck="false"
{{ live_action('setAddressLabel', {event:'input', debounce: 1000}) }} data-model="addressLabel">
<ul>
{% for key, completion in autocompletions %}
<li>
<button type="button" {{live_action('selectCompletion', {key: key})}}>
{{completion.fulltext}}
</button>
</li>
{% endfor %}
</ul>
</div><!-- bootstrap -->
<div {{attributes}} data-loading="addClass(opacity-80) addAttribute(disabled)" class="input-goup">
<input type="text" placeholder="address" class="form-control" autocomplete="false" spellcheck="false"
{{ live_action('setAddressLabel', {event:'input', debounce: 1000}) }} data-model="addressLabel">
<ul class="list-group">
{% for key, completion in autocompletions %}
<li class="list-group-item">
<button type="button" {{live_action('selectCompletion', {key: key})}} class="btn border-0 w-100 text-start">
{{completion.fulltext}}
</button>
</li>
{% endfor %}
</ul>
</div>Return Address Model with AddressTrait in same or other component.
// ...
use AddressTrait;
// ...
# return Address Model
$this->getAddress()
# return Address array
$this->getAddressArray()Twig
{{ dump(address) }}
{{ dump(addressArray) }}Address Model
string $label;
string $numero;
string $libelle;
string $codePostal;
string $ville;
string $region;
float $lat;
float $lon;
public function getLabel(): string;
public function getNumero(): string;
public function getLibelle(): string;
public function getCodePostal(): string;
public function getVille(): string;
public function getRegion(): string;
public function getLat(): float;
public function getLon(): float;