Symfony2:PHP模板中的Session Global变量

前端之家收集整理的这篇文章主要介绍了Symfony2:PHP模板中的Session Global变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Symfony doc说:

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}}?

在树枝上:{{app.session.varname}}

PHP中:echo $app-> getSession() – > get(‘uid’);

原文链接:https://www.f2er.com/php/137907.html

猜你在找的PHP相关文章