我在理解 CakePHP 中的数据库连接时遇到了一些问题。
我有一个名为 user 的表(取自 CakePHP 教程网站) 我在名为“bio”的表中添加了另一行 我可以在 bio 中插入文本,但无法检索它。 我设法通过以下方式检索了所有其他行:
$name = CakeSession::read("Auth.User.username");
$mail = CakeSession::read("Auth.User.email");
$created = CakeSession::read("Auth.User.created");
$id = CakeSession::read("Auth.User.id");
但出于某种原因,它不适用于简历。
我是否需要向 Controller 添加任何东西才能做到这一点?还是我需要设置的变量?
谢谢!
最佳答案
正如@sgt BOSE 所说。使用 CakeSession::read("Auth.User") 您将获得当前登录用户的 session 数据。
$current_user_data = $this->User->FindById(CakeSession::read("Auth.User.id"));
这将从数据库返回当前(记录的)用户数据。
关于php - Cakephp 从数据库中检索信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014583/