CakePHP:渲染未定义的索引
我调试了视图页面只是为了确认数据已正确收集。事实上我有这个:
[Friend] => Array
(
[0] => Array
(
[id] => 2
[username] => James_Baker
[password] => 7pooplllLLKMKMKKkss09koskld1d9b5e6
[first_name] => James
[last_name] => Baker
[email] => [email protected]
[group_id] => 2
[created] => 2011-01-10 08:25:52
[modified] => 2011-02-04 17:30:47
[slug] =>
....
....
当我尝试在我的视图页面上显示时,从我的 view.ctp 这是我当前使用的:
..
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo $user['Friend']['username']; ?></td>
</tr>
<?php endforeach; ?>
..
但我收到此错误:
Undefined index: username
有人可以根据我拥有的调试代码修复错误吗?我正在尝试输出/回显朋友的用户名。
I've debugged the view page just to confirm the data were properly collected. And indeed I have this:
[Friend] => Array
(
[0] => Array
(
[id] => 2
[username] => James_Baker
[password] => 7pooplllLLKMKMKKkss09koskld1d9b5e6
[first_name] => James
[last_name] => Baker
[email] => [email protected]
[group_id] => 2
[created] => 2011-01-10 08:25:52
[modified] => 2011-02-04 17:30:47
[slug] =>
....
....
As I tried displaying on my view page, from my view.ctp here's what I currently use:
..
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo $user['Friend']['username']; ?></td>
</tr>
<?php endforeach; ?>
..
but I'm getting this error:
Undefined index: username
Can someone fix the error based on the debug code I have ? I'm trying to output/echo the friend's username.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用此值的正确键是
$user['Friend'][0]['username']
要调试,请使用
var_dump($user); exit; 就在你开始每个循环之后。
Correct key to call this value is
$user['Friend'][0]['username']
To debug use
var_dump($user); exit;
just after you start every loop.听起来你想要 $user['Friend'][0]['username']
sounds like you want $user['Friend'][0]['username']