How do I get a list of bundles in symfony2/symfony3?

前端 未结 5 861
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 12:14

I\'ve just started using symfony and I\'d like to get a list of bundles from a particular vendor, iterate through them and call a $bundle->renderSomething() function on each def

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 12:50

    If you want to call a non static method of registered bundle object (not class) then you can do the following:

    $kernel = $this->container->get('kernel');
    $bundles = $kernel->getBundles();
    $bundles['YourBundleName']->someMethod();
    

    Where 'YourBundleName' is the name of your bundle, which you can get by calling from console:

    php app/console config:dump-reference
    

提交回复
热议问题