有一個cookbook用於向樹枝模板引擎添加全局變量,但是它並沒有爲php引擎做同樣的事情。我將如何做到這一點?Symfony2:php模板引擎中的全局變量
所以我可能是這樣的:
# config.yml
someSortOfReferenceToThePHPEngineInstance:
calls:
- [ addGlobals, ["foo", "bar"] ]
- [ addGlobals, ["myService", "@myService"] ]
,然後訪問那些喜歡:
// templateName.contentType.php
<?
echo $foo; // echos "bar"
echo $myService->myMethod($foo); // echos the result of modifying "bar" with "myMethod" method of "myService" service
你能寫一個你想如何做的代碼示例嗎? – greut 2012-01-09 17:19:21