我不明白如何传递包含表数据的对象数组,当模型查询返回时,这是存储在一个变量中。
所以帮帮我......
我花费更多时间来处理此错误,以便任何人对此错误有所了解
错误:
未定义变量:data文件名:employee / view_Admin_Profile.php 行号:164
行是<?php echo ($data->sub_dept_name);?>
contoller:
public function update_Admin_Profile($emp_id)
{
$data = $this->Loginm->getEmployeeProfile($emp_id);
$this->load->view('admin/header',$data);
$this->load->view('admin/sidebar',$data);
$this->load->view('employee/update_Admin_Profile',$data);
$this->load->view('admin/footer');
}
视图:
<div class="col-md-12">
<div class="form-group">
<label class="col-lg-4 control-lable">Gendar:</label>
<div class="col-lg-8">
<?php echo ($data->gender);?>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="col-lg-4 control-lable">Department Name:</label>
<div class="col-lg-8">
<?php echo ($data->sub_dept_name);?>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="col-lg-4 control-lable">Role:</label>
<div class="col-lg-8">
<?php echo ($getEmpProfile->role_name);?>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="col-lg-4 control-lable">Nationality:</label>
<div class="col-lg-8">
<?php echo ($data->nationality);?>
</div>
</div>
</div>
型号:
public function getEmployeeProfile($emp_id)
{
$this->db->select('*');
$this->db->from('employee e');
$this->db->join('sub_department sd','sd.sub_dept_id = e.sub_dept_id','left');
$this->db->join('department d','d.dept_id = sd.dept_id','left');
$this->db->join('user_role ur','ur.role_id = e.role_id','left');
$this->db->where('e.emp_id',$emp_id);
$query=$this->db->get();
if($query->num_rows() > 0)
{
return $query->row();
}
}
答案 0 :(得分:0)
public function update_Admin_Profile($emp_id)
{
//$data = $this->Loginm->getEmployeeProfile($emp_id); Your Code
$data['data'] = $this->Loginm->getEmployeeProfile($emp_id); //Change to this line
$this->load->view('admin/header',$data);
$this->load->view('admin/sidebar',$data);
$this->load->view('employee/update_Admin_Profile',$data);
$this->load->view('admin/footer');
}
and in view you can fetch like the following code:
<?php echo ($data[0]->sub_dept_name);?>
答案 1 :(得分:0)
我们举个例子: 您正从模型中获取数据,
$data = array('gender' => 'male', 'age' => 22)
然后要在codeigniter视图中访问,您需要将数组的键作为变量进行回显 例如:
<?php echo $gender; ?>