Symfony2 Sonata admin dynamically change input data based on selected value

前端 未结 3 2074
借酒劲吻你
借酒劲吻你 2021-01-03 17:11

For one of my objects I need to create some dynamic form rendering... But I cant figure out how to do this in Sonata Admin. For example when I create an object I have a fiel

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-03 17:53

    If I have realy understand your need you have to use ajax of course, first you need to add new admin route to this EntityAdminController to do it you have to override the configureRoutes method and to add your new route like this :

    protected function configureRoutes(RouteCollection $collection)
    {
        $collection->add('reloadCities', 'realod-cities');
    }
    

    Then you have to create a new controller which gonna have the action definition for your new route like :

    use Sonata\AdminBundle\Controller\CRUDController as BaseController;
    
    
    class CitiesController extends BaseController
    {
        public function reloadCitiesAction()
        {
            // some code
            return $this->render(...);
        }
    }
    

    Then you have to override the SonataAdminBundle:CRUD:edit.html.twig template and set your javascript event listener like this :

    {% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}
    
    {% block form %}
        {{ parent() }}
    
    

提交回复
热议问题