0

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>
David
  • 33
  • 1
  • 7
  • Possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) (Specifically, this section: http://stackoverflow.com/a/26572398/1427878) – CBroe Jan 24 '17 at 11:57
  • @David try below answer. – Hikmat Sijapati Jan 24 '17 at 12:46

2 Answers2

1

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
    }
}
davidc2p
  • 320
  • 3
  • 9
0

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.

Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19