【发布时间】:2019-12-19 22:24:48
【问题描述】:
我正在从我的数据库中提取特定实体的数据,并形成与它们相关的其他表。
当 db 中的某个对象为空时,如何跳过错误?
错误是:
在 null 时调用成员函数 getName()
代码:
$results = $this->getMyRepository()->findAll();
$rows = [];
$rows[] = array(
"id",
"user",
"category"
);
foreach ($results as $row) {
$rows[] = [
$row->getId(),
$row->getUser()->getFullName(),
$row->getCategory()->getName(),
];
}
return $rows;
}
【问题讨论】:
标签: php arrays class symfony-3.4