我一直试图从蛋糕中提取数据。但是当我通过print_r
查看时,我继续获取对象数据$userDetails = $this->UserDetails->find()->where(['UserDetails.user_id' => $id])->all();
print_r($userDetails);
结果
Cake\ORM\ResultSet Object ( [items] => Array ( [0] => App\Model\Entity\UserDetail Object ( [id] => 6 [user_id] => 10 [firstName] => Rey Norbert [lastName] => Besmonte [address] => [contact] => [age] => [created] => Cake\I18n\FrozenTime Object ( [time] => 2017-05-24T03:10:55+00:00 [timezone] => UTC [fixedNowTime] => ) [modified] => Cake\I18n\FrozenTime Object ( [time] => 2017-05-24T03:10:55+00:00 [timezone] => UTC [fixedNowTime] => ) [[new]] => [[accessible]] => Array ( [*] => 1 [id] => ) [[dirty]] => Array ( ) [[original]] => Array ( ) [[virtual]] => Array ( ) [[errors]] => Array ( ) [[invalid]] => Array ( ) [[repository]] => UserDetails ) ) )
我不确定ake\ORM\ResultSet Object ( [items] => Array ( [0] => App\Model\Entity\UserDetail Object
显示的原因。
在php cake 2.x中我对此没有任何问题。
答案 0 :(得分:1)
Cakephp 3.x输出对象而不是array()。 如果你想要阵列,你可以 e toArray();
示例: - 强>
$userDetails = $this->UserDetails->find('all')->where(['UserDetails.user_id' => $id])->toArray();
print_r($userDetails);
如果您只想返回单行,那么您可以使用 first()
示例: - 强>
$userDetails = $this->UserDetails->find('all')->where(['UserDetails.user_id' => $id])->first();
print_r($userDetails);
答案 1 :(得分:0)
根据您的要求使用其中任何一项:
$userDetails = $this->UserDetails->find()->where(['UserDetails.user_id' => $id])->all();