我希望从DataBase获得Globals,我可以吗?
# app/config/parameters.yml
twig:
globals:
siteName: 'here site name from database'
答案 0 :(得分:1)
您可以创建一个TwigExtension(http://symfony.com/doc/current/cookbook/templating/twig_extension.html和http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension),在其中注入EntityManager并在那里注册全局变量。
答案 1 :(得分:0)
在BaseController中加载全局值
$this->get('twig')
->addGlobal(
'global1',
$this->em
->getRepository('MyBundle:Globals')
->getGlobalOne());