Trying to get property of non-object

2019-09-24 05:35发布

问题:

I'm trying to pass id of user from one view to another and display profile details of respective id.But instead of displaying profile details i get error message "trying to get property of non-object.

Here is the first view

<td class="user-name"><a href="<?php echo site_url() . 'admin/users/members_details/' . $allusers->p_u_id; ?>"> <?php echo $allusers->comp_person_name ?></a>   <span>Subscriber</span> </td>

controllers : members_details method

public function members_details () {
     $data['udetails']= $this->user_model->user_details(array('u_id' => $this->uri->segment(4) , 'u_delete' => 1 ));
 $this->layout->view("admin/members_details", $data);
}

user_details model

 function user_details($where = '', $order = '', $select = '') {
        if (!$select)
            $select = array('users.u_id', 'users.u_email', 'u_status', 'u_group', 'user_profile.*', 'cities.*', 'country.*');

        $joins = array(array('table' => 'user_profile', 'condition' => 'user_profile.p_u_id=users.u_id', 'jointype' => 'INNER'),
            array('table' => 'cities', 'condition' => 'user_profile.comp_city=cities.id', 'jointype' => 'INNER'),
            array('table' => 'country', 'condition' => 'user_profile.comp_country=country.id', 'jointype' => 'INNER'));
        if ($order)
            $this->db->order_by($order);
        else
            $this->db->order_by('u_id  DESC');

        return $this->get_joins('users', $where, $joins, $select);
    }

members_details view

<a href="#" class="user-name">
<?php echo $udetails->comp_person_name ?> 
<span class="user-status is-online"></span>

Now when i trying to display comp_person_name , i get above said error. Where i went wrong?

回答1:

data returns an array .So replacing

 $udetails->comp_person_name  

with

$udetails['0']->comp_person_name

solved the issue