如何处理此错误?
遇到PHP错误
严重性:注意
消息:尝试获取非对象的属性
文件名:views / email_templates.php
行号:57
回溯:
文件:C:\ Program Files(x86)\ EasyPHP-DevServer-14.1VC9 \ data \ localweb \ EcommerceGiondaCI \ application \ views \ email_templates.php 行:57 功能:_error_handler
文件:C:\ Program Files(x86)\ EasyPHP-DevServer-14.1VC9 \ data \ localweb \ EcommerceGiondaCI \ application \ controllers \ Cpages.php 行:596 功能:查看
文件:C:\ Program Files(x86)\ EasyPHP-DevServer-14.1VC9 \ data \ localweb \ EcommerceGiondaCI \ index.php 行:315 功能:require_once
视图/ 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>
模型/ pages_model.php
public function call_email()
{
$query = $this->db->get('email');
return $query->result_array();
}
视图/ email_templates.php 行号:57
Line 57: <td><?php echo $email_item->email_title; ?>account_invitation</td>
答案 0 :(得分:1)
根据你想要修复的内容(调用模型的结果,或者它可能给出的空结果),我会在尝试使用之前测试数组是否存在:
urlLoader.load(request);
答案 1 :(得分:0)
在你的模特中。试试这个..
public function call_email() {
$query = $this->db->get('email');
return $query->result();
}
result_array()
以数组格式获取行。但是您可以使用result()
获取对象格式的结果,因为在视图中您可以使用箭头操作符访问元素。有关详情,请参阅https://www.codeigniter.com/userguide3/database/results.html
希望它能完美运作。