加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Symfony2:PHP模板中的Session Global变量

发布时间:2020-12-13 13:34:57 所属栏目:PHP教程 来源:网络整理
导读: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 v
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
SymfonyComponentHttpFoundationSession could not be converted to
string in C:wampwww…

在PHP模板方面缺乏资源,但在我的情况下,由于某些原因我无法切换.

换句话说,问题在于PHP模板的等价物:
{{app.session.varname}}?

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读