【发布时间】:2016-09-10 19:14:33
【问题描述】:
我对 codeigniter 有疑问。这是消息
遇到 PHP 错误
严重性:通知
消息:试图获取非对象的属性
文件名:员工/detail.php
行号:15
我有这样的模型:
public function getByID($id){
$this->db->select('*');
$this->db->from('master_employee me');
$this->db->join('master_position mp', 'mp.mp_id=me.mp_id');
$this->db->where('me.me_id', $id);
$query = $this->db->get();
return $query->row();
}
控制器:
public function edit($id){
/**
* [$data get data from database]
* @var array
*/
$data = array($id);
$data['msg'] = $this->_get_flashdata();
$data['rows'] = $this->m_employee->getByID($id);
$data['position'] = $this->m_position->get();
/**
* [$html call all wireframe]
* @var array
*/
$html = array();
$html['header'] = $this->load->view('admin/header',$data,true);
$html['kiri'] = $this->load->view('admin/kiri',null,true);
$html['content'] = $this->load->view('admin/employee/edit',$data,true);
$this->load->view('admin/template',$html);
}
并像这样查看
<?php if($rows->me_photo == NULL): ?>
<img src="<?php echo base_url('/upload/be/employee/default-no-image.png'); ?>" class="img-responsive" title="no-photo" style="margin-bottom:10px" />
<?php else: ?>
<img src="<?php echo base_url('/upload/be/employee'.$rows->me_name); ?>" class="img-responsive" style="margin-bottom:10px" />
<?php endif; ?>
如何解决我的问题?请
【问题讨论】:
-
您是否遵循
Some_model.php和class Some_model extends CI_Model{}以及Some_other_class.php和Some_other_class extends CI_Controller{}中的名称标准化和样式指南规则,如documentations 中所述?在版本 3+ 中更重要(注意 ucfirst() 规则)? -
您能告诉我上面代码中的第 15 行是哪一行吗?此错误意味着您的模型没有获得任何记录返回。您的视图文件中的 me_name 属性是什么?
-
或者你可能指向了错误的属性(数据库列名)
标签: php codeigniter