How to get current bundle in Symfony 2?

后端 未结 4 1019
盖世英雄少女心
盖世英雄少女心 2021-02-03 11:09

How can I detect in which bundle am I?

for exemple, when I\'m in web.com/participants/list, I want to read \"participants\".

4条回答
  •  暖寄归人
    2021-02-03 11:59

    In order to get the bundle name in the controller:

    // Display "AcmeHelloBundle"
    echo $this->getRequest()->attributes->get('_template')->get('bundle');
    

    And inside a Twig template:

    {{ app.request.get('_template').get('bundle') }}
    

    In order to get the controller name in the controller:

    // Display "Default"
    echo $this->getRequest()->attributes->get('_template')->get('controller');
    

    And inside a Twig template:

    {{ app.request.get('_template').get('controller') }}
    

    In order to get the action name in the controller:

    // Displays "index"
    echo $this->getRequest()->attributes->get('_template')->get('name');
    

    And inside a Twig template:

    {{ app.request.get('_template').get('name') }}
    

提交回复
热议问题