Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An exception has been thrown during the rendering of a template #139

Open
devkbsc opened this issue Mar 13, 2019 · 0 comments
Open

An exception has been thrown during the rendering of a template #139

devkbsc opened this issue Mar 13, 2019 · 0 comments

Comments

@devkbsc
Copy link

devkbsc commented Mar 13, 2019

Hello,
I have used this autocomplete bundle in my project. I have encounted an error. I am sure that i have mistaken something in the steps which have been mentioned in the documentation. But i am really worried about which one i have missed. It seems like it work for autocompte doctrine mapping field

Here is my sourcecode

SocieteController.php

public function autocompleteAction(Request $request)
    {
        // Check security etc. if needed
    
        $as = $this->get('tetranz_select2entity.autocomplete_service');

        $result = $as->getAutocompleteResults($request, \BlogBundle\Form\DossierType::class);

        return new JsonResponse($result);
    }

DossierType.php

public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder->add('noDossier', TextType::class, ['label' => 'N° Dossier', 'attr' => ['class' => 'form-control bottom15 top15']])
                ->add('nomDossier', TextType::class, ['label' => 'Nom Dossier', 'attr' => ['class' => 'form-control bottom15 top15']])
                
                ->add('societe', Select2EntityType::class, [
                    //'multiple' => true,
                    'primary_key' => 'id',
                    'remote_route' => 'autocomplete_societe',
                    'class' => Societe::class,
                    'minimum_input_length' => 2,
                    'page_limit' => 10,
                    'allow_clear' => true,
                    'property' => 'nom',
                    'delay' => 250,
                    'cache' => true,
                    'cache_timeout' => 60000, // if 'cache' is true
                    'language' => 'fr',
                    'placeholder' => 'Séléctionnez une société',
                        // 'object_manager' => $objectManager, // inject a custom object / entity manager 
                ])
}

Societe Entity

class Societe {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    private $nom;

Societe-section.html.twig which in included in dossier/master.html.twig

<div class="col-md-6">
        {% block tetranz_select2entity_widget_select_option %}
            <option value="{{ label.id }}" selected="selected"
                    {% for key, data in label %}
                        {% if key not in ['id', 'nom'] %} data-{{ key }}="{{ data }}"{% endif %}
                    {% endfor %}>
                {{ label.text }}
            </option>
        {% endblock %}
    </div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant