Blogger Information
Blog 3
fans 0
comment 0
visits 4392
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp 模板文件中输出session值的三种方法
php菜鸟-从1学起
Original
1739 people have browsed it

一、起因

参考了thinkphp的官方文档,使用{$Think.session.xxxx}在html模板文件中输出$_SESSION['username']的值,但是步成功,一直布显示,也没有报错,于是上网查了一下,清一色的还是按照官方文档的方法,但是我这样做就不行,于是搜到了下面这篇回答,试了之后可行,贴出来给大家参考:

二、解决方法

{:session('xxxx')},这个冒号后面就可以直接跟函数了,可以获取设置都没问题;
用的是这种方法,还是标签,也没有明显的写入php代码的痕迹: {:$_SESSION['xxxx']}

另外一种是直接用thinkphp的模板系统变量{$Think.session.xxxx}

不太推荐的方法,可以直接用<php>echo session('xxxx');</php>或者<?php echo session('xxxx');?> 都是可以的,因为thinkphp模板最后还是要生成php文件的,所以可以直接把这个模板看成php文件。



作者:悦凡漫思
链接:https://www.jianshu.com/p/cc10e7362666
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!