Cakephp从数据库检索信息
我在理解CakePHP中与数据库的连接时遇到了一些问题。
I'm having some problems understanding the connection to the database in CakePHP.
我有一个名为user的表(取自CakePHP教程网站)在表格中添加了另一行称为 bio,我可以将文本插入到bio中,但是我无法检索到它。
我设法通过以下方式检索所有其他行:
I have a table called user (which was taken from the CakePHP tutorial website) I added another row to the table called "bio" I am able to insert text into the bio but i'm not able to retrieve it. I've managed to retrieve all the other rows by:
$name = CakeSession::read("Auth.User.username");
$mail = CakeSession::read("Auth.User.email");
$created = CakeSession::read("Auth.User.created");
$id = CakeSession::read("Auth.User.id");
但由于某些原因,它不适用于生物。
but for some reason it won't work with the bio.
我是否需要向控制器添加任何东西才能做到这一点?还是我需要设置的变量?
Do I need to add anything to controllers to be able to this? Or is it a variable that I need to set?
谢谢!
如@sgt BOSE所说。使用CakeSession :: read( Auth.User),您将获得当前登录用户的会话数据。
As @sgt BOSE said. Using CakeSession::read("Auth.User") you will get session data of your current logged user.
$current_user_data = $this->User->FindById(CakeSession::read("Auth.User.id"));
这将从数据库中返回当前(记录)的用户数据。
This will return current (logged) user data from database.