Reputation: 33
How to handle this error?
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/email_templates.php
Line Number: 57
Backtrace:
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\EcommerceGiondaCI\application\views\email_templates.php Line: 57 Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\EcommerceGiondaCI\application\controllers\Cpages.php Line: 596 Function: view
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\EcommerceGiondaCI\index.php Line: 315 Function: require_once
views/email_templates.php
<?php foreach ($email as $email_item): ?>
<tr>
<td><?php echo $email_item->email_title; ?>account_invitation</td>
<td>preview</td>
<td><button type="button" class="edit" onclick="location.href = '<?php echo site_url('cpages/editemailtemplate/'.$email_item->email_id); ?>';">EDIT</button></td>
<td><button type="button" class="delete" href="adminform.php">DELETE</button></td>
</tr>
models/pages_model.php
public function call_email()
{
$query = $this->db->get('email');
return $query->result_array();
}
views/email_templates.php Line Number: 57
Line 57: <td><?php echo $email_item->email_title; ?>account_invitation</td>
Upvotes: 0
Views: 331
Reputation: 6969
In your Model.Try like this..
public function call_email() {
$query = $this->db->get('email');
return $query->result();
}
result_array()
gets row in array format.But for you get result in object format using result()
because in view you accessing elements using arrow operator.For more see https://www.codeigniter.com/userguide3/database/results.html
Hope it will work perfectly.
Upvotes: 0
Reputation: 320
Depending of what you want to fix (either the result to the call to your model, or the empty result it might give), I would test the array for existence before trying to use it:
if (isset($email)) {
if (is_array($email)) {
//your code here
}
}
Upvotes: 1