UserController的如何在CakePHP中显示登录用户的记录?
public function profile()
{
$this->set('profile', $this->User->find('all'));
}
profile.ctp
<?php
echo $profile['User']['name']; // Where user is the model and name is the name field in db.
?>
我知道我做错了什么,但我找不到它的任何好的解决方案。
我们将如何在视图中回应它? –
鉴于现在你有记录,试着做一个var_dump($ profile),你可以看到所有的字段。但如果你想尝试:echo $ profile ['User'] ['name'];或echo $ profile [0] ['User'] ['name'];我不知道你的数组是如何取决于你的模型之间的关系, –
它的工作,非常感谢你:) –