I build a query which does return results since i var dump the objects, however, when I loop through the results, I get an error during the loop stage.
I have tried to looking on online as to why I am getting the error, including the php documentation.
Here is my 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);
Here is my If fucntion with a foreach loop.
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
])
);
Here is the error I am getting in return
Fatal error: Call to a member function getStatus() on array
What I am trying to do is do a query, get the results that will pass the objects to a twig template
varDump Resutl
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"
}
}