我想以员工的名义链接.....当我点击任何名称然后显示他的详细信息....我创建此代码..有些错误“试图获取非对象的属性” ....请帮帮我......
1.controller
function abc($id = 0)
{
$this->load->model('emp_model');
$data['rows'] = $this->emp_model->get();
$this->load->view('personal_emp',$data);
}
2.models
function get($id)
{
$this->load->database();
return $this->db->get_where('employee',array('id'=>$id))->row_array();
}
3.views
<table border="1" height="200" width="200" bordercolor="#003366" align="center">
<tr>
<th>ID</th></td>
<th>NAME</th>
<th>Fathet Name</th>
<th>Dob</th>
<th>Qualification</th>
<th>Identity Type</th><th>Identity No</th>
<th>Gender</th>
<th>Email</th>
<th colspan='2'>Action</th>
</tr>
<?php foreach($rows as $r)
{
echo "<tr>";
echo "<td>". $r->id ."</td>";
echo "<td>". $r->name ."</td>";
echo "<td>". $r->father_name ."</td>";
echo "<td>". $r->dob ."</td>";
echo "<td>". $r->qualification ."</td>";
echo "<td>". $r->identity_type ."</td>";
echo "<td>". $r->identity_no ."</td>";
echo "<td>". $r->gender ."</td>";
echo "<td>". $r->email ."</td>";
echo "<td>". anchor('employee/input/'.$r->id,'Edit') ."</td>";
echo "<td>". anchor('employee/del/'.$r->id,'Delete') ."</td>";
echo "</tr>";
echo "<br>";
}
?>
</table>
答案 0 :(得分:1)
对于初学者,您需要为变量命名,在本例中为数组键。然后你需要调用正确的方法。不是general()
而是get()
。
function abc($id = 0)
{
$this->load->model('emp_model');
$data['rows'] = $this->emp_model->get();
$this->load->view('personal_emp',$data);
}
轻微修改方法
function get($id)
{
$this->load->database();
return $this->db->get_where('employee',array('id'=>$id))->result();
}
希望这会有所帮助。玩得开心!