0

I'm not understand how to pass array of object which contain data of table and this is store in one variable when model query return..

so help me...

more time im spend on this error so if any one have idea on this error

Error :

Undefined variable: data Filename: employee/view_Admin_Profile.php Line Number: 164

at line is <?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');
   }

view:

<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>

Model :

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();
            }
        }
Sofyan Thayf
  • 1,322
  • 2
  • 14
  • 26
shree
  • 11
  • 4

2 Answers2

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);?>
0

Let's take the example: You are getting the data from model like,

$data = array('gender' => 'male', 'age' => 22)

Then to access in codeigniter view you need to echo array's key as a variable example:

<?php echo $gender; ?>