Ir al artículo

Controller Code - Github

    /**
     * @Route("/autocomplete-forms", name="examples_autocomplete_forms")
     * @Template()
     */
    public function autocompleteFormAction()
    {
        $em = $this->getDoctrine()->getManager();

        $cities = $em->getRepository('MainBundle:City')->findAll();

        return array(
            'cities' => $cities,
        );
    }

Template Code - Github

{% extends 'MainBundle::layout.html.twig' %}

{% import 'MainBundle:Macros:breadcrumb.html.twig' as breadcrumb %}

{% set section = 'examples' %}

{% block breadcrumb %}
{{ breadcrumb.show_example('Autocompletado de un campo en Symfony2') }}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-md-12">
            <ul class="list-group">
                <li class="list-group-item"><a href="{{ path('examples_autocomplete_forms_select_city') }}">Seleccionar ciudad</a></li>
                <li class="list-group-item">
                    Editar una ciudad:
                    <ul>
                        {% for city in cities %}
                            <li><a href="{{ path('examples_autocomplete_forms_select_city_edit', {'slug': city.slug}) }}">{{ city.name }}</a></li>
                        {% endfor %}
                    </ul>
                </li>
            </ul>
        </div>
    </div>
{% endblock %}


{% set article_link = 'http://showmethecode.es/php/symfony/autocompletado-de-un-campo-en-symfony2/' %}

Fork me on GitHub