I got this error message when running PHP Code Igniter project:
A PHP Error was encountered Severity: Warning
Message: Undefined property: stdClass::$cancelled
Filename: transactions/transtable.php
Line Number: 38
Backtrace:
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\views\transactions\transtable.php Line: 38 Function: _error_handler
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\controllers\Search.php Line: 103 Function: view
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\index.php Line: 315 Function: require_once
Here is the code where the error occurs.
<?php foreach($allTransactions as $get): ?>
<tr>
<th><?= $sn ?>.</th>
<td><a class="pointer vtr" title="Click to view receipt"><?= $get->ref ?></a></td>
<td><?= $get->quantity ?></td>
<td>₵<?= number_format($get->totalMoneySpent, 2) ?></td>
<td>₵<?= number_format($get->amountTendered, 2) ?></td>
<td>₵<?= number_format($get->changeDue, 2) ?></td>
<td><?= str_replace("_", " ", $get->modeOfPayment)?></td>
<td><?=$get->staffName?></td>
<td><?=$get->cust_name?> - <?=$get->cust_phone?> - <?=$get->cust_email?></td>
<td><?= date('jS M, Y h:ia', strtotime($get->transDate)) ?></td>
<td><?=$get->cancelled? 'Cancelled' : 'Completed'?></td>
</tr>
<?php $sn++; ?>
<?php endforeach; ?>
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\views\transactions\transtable.php Line: 38 Function: _error_handler
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\controllers\Search.php Line: 103 Function: view
public function transSearch()
{
$data['allTransactions'] = $this->transaction->transsearch($this->value);
$data['sn'] = 1;
$json['transTable'] = $data['allTransactions'] ? $this->load->view('transactions/transtable', $data, TRUE) : "No match found";
//set final output
$this->output->set_content_type('application/json')->set_output(json_encode($json));
}
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\index.php Line: 315 Function: require_once
require_once BASEPATH.'core/CodeIgniter.php';
Using isset()
function to check is property have value
<td><?= isset($get->cancelled) ? 'Cancelled' : 'Completed' ?></td>
Or using property_exists()
function to check if object have the key.
<td><?= property_exists($get, 'cancelled') ? 'Cancelled' : 'Completed' ?></td>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.