尝试使用codeigniter获取非对象错误的属性

时间:2016-05-14 17:03:32

标签: php codeigniter

我对codeigniter有疑问。这是消息

  

遇到PHP错误

     

严重性:注意

     

消息:尝试获取非对象的属性

     

文件名:employee / 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; ?>

如何解决我的问题?请

2 个答案:

答案 0 :(得分:0)

试试这个:

exec("cmd /c C:\\xampp\\mysql_start.bat > tmp.txt 2>&1");

它是一个数组。不反对。 <?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" /> 代表对象。
您需要像->一样更改$rows->m_ephoto

答案 1 :(得分:0)

修改您的查询

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->result();
}

在视图中使用像这样

foreach ($query->result() as $row){
    echo $row->title;
 }

<强> read here i hope you will get the answer