我正在检索一堆数据,由于某种原因,一些数据被损坏了。例如,我有一些 Post 模型,每个模型都与 Comment 模型(hasMany)相关,并且每个 Comment 模型都属于一个用户。检索数据时,这是我从数据库中获得的评论:
[Post] => Array
(
)
[Comments] => Array
(
[0] => Array
(
[content] => "2010 has definitely been a busy year!"
[created] => 2010-02-10 13:47:15
[user_id] => 18
[post_id] => 1
[User] => Array
(
[id] => U8
[username] => Uace
[first_name] => Uace
)
[_explicitType] => Comment
)
[0] => Array
(
[content] => "I can't wait..."
[created] => 2009-12-10 13:57:36
[user_id] => 18
[post_id] => 1
[User] => Array
(
[id] => U8
[username] => Uace
[first_name] => Uace
)
[_explicitType] => Comment
)
)
每个 Comments[i][User] 数组的第一个字符已被替换为大写 U,尽管在每种情况下它都应该不同(例如 ID 为 18,用户名 Jace 等)。
我将其追溯到我正在使用的数组操作,以在 afterFind() 函数中为 Flex 交互分配一个 _explicitType 字段(谢谢,Paweł Mysior!)。这是我停留在 _explicitType 中的循环:
if (is_array($results)) {
foreach ( $results as &$item )
{
$item['_explicitType'] = $this->name;
}
} else {
$item[$this->name]['_explicitType'] = $this->name;
}
我认为它与引用分配有关,但我想不出它为什么会发生。