0

我正在为 CakePHP 2.x 中的 auth-componentent 苦苦挣扎 这本书在这里说 (底部的最后一个条目)

$this->Auth->user();

如果参数为空,则返回所有用户数据。

"$key (string) – The user data key you want to fetch. 
If null, all user data will be returned."

但如果我回声$u

$u = $this->Auth->user();

然后只显示用户ID。我期望整个用户数组。有任何想法吗?

4

6 回答 6

1
$this->Auth->user();

返回值是数组,因此如果您只想打印整个内容以进行调试,请尝试

$u = $this->Auth->user();
var_dump($u);

或者

print_r($u);
于 2014-01-06T18:02:03.337 回答
0

As Mark (DerEuroMark) expected in the comment, my login script was wrong. For some reason I stored the array too flat. The login code was wrong. I fixed the login code (respectively I wrote it from scatch and now everything works fine. Thank you anyway for all the replies.

于 2014-01-06T20:12:02.667 回答
0

$u = $this->Auth->user();

返回一个关联数组,您可以通过表中的键访问字段,例如

echo $u['username']; 
echo $u['email'];
于 2014-01-06T18:14:22.113 回答
0

$u = $this->Auth->user();

Yes you are trying echo $u;

在下面尝试此尝试

vardump($u); or print_r($u);

如果这对你有帮助,现在让我说。

谢谢

于 2014-01-06T18:14:28.553 回答
0

试试这个代码............ pr($this->Auth->user());

于 2014-01-07T07:14:09.690 回答
-1
 $this->Auth->user();

从用户表返回数据,您应该使用

 $id= $this->Auth->user('id');

获取 id

于 2014-01-06T17:48:06.563 回答