Arrays 通过findall()将原则对象返回到array/json-在对象上给出错误-的
我在第10行遇到一个错误: 对中的非对象调用成员函数getUserId()Arrays 通过findall()将原则对象返回到array/json-在对象上给出错误-的,arrays,json,symfony,Arrays,Json,Symfony,我在第10行遇到一个错误: 对中的非对象调用成员函数getUserId() /** @var $users User*/ $users= $this->getRepository("repo")->findAll(); $response = array(); foreach ($users $user) { $response[] = array( **line10 'user_id' => $user-&
/** @var $users User*/
$users= $this->getRepository("repo")->findAll();
$response = array();
foreach ($users $user) {
$response[] = array(
**line10 'user_id' => $user->getUserId()
);
}
基本上在第10行中,它没有识别对getUserId的调用
那么,如何将数据提取到数组或json?
感谢在
$campetings
的循环中,数组的一个元素似乎是null
,因此此元素没有方法getUserId
。尝试var_dump
您的$campaings
数组来检查其内容,我很确定您将能够在之后找到错误。尝试:$campaings=$this->getdoctor->getrepo->findAll()代码>看起来像是$campetings
没有结果,请尝试:
if($capaigns) {
foreach ($campaigns as $user) {
$response[] = array('user_id' => $user->getUserId());
}
}
var dump为数据库中的实体对象提供了正确的数据campagins/user包含实体对象,并且数据是正确的,仅在内部存在问题