当我从 session 中调用它时,我无法让我的用户名显示在网站上。
index页面的代码是:
<h1>Users Home</h1>
Welcome <?php $user = $this->Session->read('Users.username');?>
我做错了什么?
我也尝试过各种其他调用它的方法,然后收到不同的错误消息。
最佳答案
在您的代码中,您使用用户名的内容设置 $user。但是你没有打印它。
<h1>Users Home</h1>
Welcome <?=$this->Session->read('Auth.User.username')?>
这是
的缩写<h1>Users Home</h1>
Welcome <?php print $this->Session->read('Auth.User.username'); ?>
关于php - 如何在 cakephp 中使用 session 打印用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13706707/