Ir al artículo

Controller Code - Github

    /**
     * @Route("/selects-dependientes", name="examples_dependent_selects")
     * @Template()
     */
    public function dependentSelectsAction()
    {
        $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('Selects Dependientes') }}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-md-12">
            <ul class="list-group">
                <li class="list-group-item"><a href="{{ path('examples_dependent_selects_location_new') }}">Crear Localización</a></li>
                <li class="list-group-item">Editar Localización
                    <ul>
                        {% for city in cities %}
                            <li><a href="{{ path('examples_dependent_selects_location_edit', {'slug': city.slug}) }}">{{ city.name }}</a></li>
                        {% endfor %}
                    </ul>
                </li>
            </ul>
        </div>
    </div>
{% endblock %}


{% set article_link = 'http://showmethecode.es/php/symfony/symfony2-selects-dependientes-mediante-eventos/' %}

Fork me on GitHub