我正在使用cake 2.0,我试图在我的视图中打印出以下内容。即一个用户的朋友,我无法理解如何将其打印出来。即时通讯使用HABTM关系,它似乎正在发挥作用。
控制器发送一个名为" $ users"的变量。视图,但我似乎无法正确打印出来(我不太熟悉Php阵列')
任何人都可以帮助我(调试$ users)
Array
(
[0] => Array
(
[User] => Array
(
[id] => 104
[username] => admin
)
[Friend] => Array
(
[0] => Array
(
[id] => 107
[username] => carskitchens
[Retailerrelationship] => Array
(
[id] => 12
[retailer_id] => 104
[supplier_id] => 107
[created] => 2012-03-28 10:14:23
[modified] => 2012-03-28 10:14:23
)
)
[1] => Array
(
[id] => 112
[username] => manufacturer
[Retailerrelationship] => Array
(
[id] => 13
[retailer_id] => 104
[supplier_id] => 112
[created] => 2012-03-28 11:26:52
[modified] => 2012-03-28 11:26:52
)
)
)
)
)
答案 0 :(得分:1)
没有任何格式化,循环将是:
foreach($users as $user)
{
echo $user['User']['name'];
foreach($user['Friend'] as $friend)
{
echo $friend['username'];
}
}