During each request,Symfony2 will set a global template variable app
in both Twig and PHP template engines by default. The app variable is
a GlobalVariables instance which will give you access to some
application specific variables automatically:
app.security – The
security context.
app.user – The current user object.
app.request – The request object.
app.session – The session
object.
app.environment – The current environment (dev,prod,
etc).
app.debug – True if in debug mode. False otherwise.
例子:
在树枝上:{{app.request.method}}
在PHP中:echo $app-> getRequest() – > getMethod()
在树枝上:{{app.user.username}}
但对于会话对象:
在树枝上:{{app.session.varname}}
用PHP://我不知道,你知道如何调用吗?
我试过了:$session = $app-> getSession(‘uid’);但当我尝试将其存储到数据库时,它告诉我:
Catchable Fatal Error: Object of class
Symfony\Component\HttpFoundation\Session could not be converted to
string in C:\wamp\www…
在PHP模板方面缺乏资源,但在我的情况下,由于某些原因我无法切换.
换句话说,问题在于PHP模板的等价物:
{{app.session.varname}}?
在PHP中:echo $app-> getSession() – > get(‘uid’);