我构建了一个查询,该查询不会返回结果,因为我是var转储对象,但是,当我循环遍历结果时,在循环阶段会出现错误。
我试图在线查找我为什么得到此错误,包括php文档。
这是我的querybuilder。
/** @var QueryBuilder $qb */
$qb = $repository->createQueryBuilder('i');
$qb->select('j.fund_code', 'j.amount', 'i.source_code',
'i.keyword', 'i.created_at', 'i.status', 'g.transaction_id')
->join('i.gateway_response', 'g')
->join('i.items', 'j')
->Where("i.status = :status")
->andWhere($qb->expr()->between('i.created_at',
':starts_at', ':ends_at'))
->setParameter('status', 2)
->setParameter('starts_at', $startsAt,
\Doctrine\DBAL\Types\Type::DATETIME)
->setParameter('ends_at', $endsAt,
\Doctrine\DBAL\Types\Type::DATETIME)
;
$query = $qb->getQuery();
$results = $query->getResult();
$resultCount = count($results);
var_dump($results);
这是我的带有ifeach循环的If功能。
if($resultCount > 0) {
foreach($results as $holdTran) {
$status = $holdTran->getStatus();
}
$output->writeln($resultCount . ': Transactions on Hold');
$output->writeln($status);
$mailer = $this->getContainer()->get('mailer');
$message = new \Swift_Message();
$message
->setSubject('Daily Giving Report')
->setFrom('chris2kus31@gmail.com')
->setTo('cmoreno@kcm.org')
->setContentType("text/html")
->setBody($this->getContainer()->get('templating')-
>render('@Giving/Default/givingReport.html.twig',
[
'resultCount' => $resultCount,
'status'=> $status
])
);
这是我得到的错误
致命错误:在数组上调用成员函数getStatus()
我想做的是查询,获取将对象传递到树枝模板的结果
varDump结果
array(1) {
[0] =>
array(7) {
'fund_code' =>
string(4) "K100"
'amount' =>
double(20)
'source_code' =>
NULL
'keyword' =>
NULL
'created_at' =>
class DateTime#675 (3) {
public $date =>
string(26) "2019-03-26 08:03:20.000000"
public $timezone_type =>
int(3)
public $timezone =>
string(15) "America/Chicago"
}
'status' =>
int(2)
'transaction_id' =>
string(12) "000035772641"
}
}