我的模型页面中有这个代码:
public function getAll($researcherpk){
$this->db->select('*');
$this->db->from('research');
$this->db->join('researcher', 'researcher = lastname');
$this->db->where('researcherpk', $researcherpk);
return $this->db->get()->row_array();
Run Code Online (Sandbox Code Playgroud)
但是当我在View页面上使用它时
Age: <?php echo $data['age'];?> // this work
<?php foreach ($data as $v){ ?> //this has an error
<tr>
<td><?php echo $v->title?></td>
<td><?php echo $v->track_records?></td>
</tr>
<?php } ?>
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Message: Trying to get property of non-object
Run Code Online (Sandbox Code Playgroud)
在我的控制器页面中:
public function researcher($researcherpk){
$this->load->model('ResearchModel');
$result['data'] = $this->ResearchModel->getAll($researcherpk);
$this->load->view('researcher',$result);
}
Run Code Online (Sandbox Code Playgroud)
您认为这里的问题是什么?对于它或更改,我的替代解决方案是什么?