PHP code example of localinks / dependentautocompletebundle

1. Go to this page and download the library: Download localinks/dependentautocompletebundle 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/ */

    

localinks / dependentautocompletebundle example snippets



...
public function registerBundles()
{
    $bundles = array(
        ...
        new Localinks\DependentAutoCompleteBundle\LocalinksDependentAutoCompleteBundle(),
        ...
    );
...


...
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('country', 'sonata_type_model_autocomplete', array(
                'label' => 'Country',
                'property' => 'name',
                'attr' => array('data-dependent-id' => 'country'),
                '      $request = Request::createFromGlobals();
                        $dependencies = $request->get('dependencies');

                        $datagrid = $admin->getDatagrid();
                        $queryBuilder = $datagrid->getQuery();

                        if(!is_null($dependencies['country_id']) && $dependencies['country_id'] !== "") {
                            $queryBuilder
                                ->leftJoin($queryBuilder->getRootAlias() . '.country', 'cco')
                                ->where($queryBuilder->getRootAlias() . '.' .$property . ' LIKE :value')
                                ->andWhere('cco.id = :country_id')
                                ->setParameters(array(
                                    'country_id' => $dependencies['country_id'],
                                    'value' => $value . '%'
                                ));
                            }
                        else {
                            $queryBuilder
                                ->where($queryBuilder->getRootAlias() . '.' .$property . ' LIKE :value')
                                ->setParameters(array(
                                    'value' => $value . '%'
                                ));
                        }
                    },
                    '

    php composer.phar update