Welcome Guest, Not a member yet? Register   Sign In
model is not return data to controller.
#1

Hi, I am facing strange issue.

My model have a result from DB, when I debug it in model it gives me result but when I return it to controller it gives empty object. any suggestion ?

HERE is my Controller code

function editCompanyForm($companyId) {
      $this->load->model('Company');
      $company = $this->Company->getCompanyById($companyId);
      debug($company);exit; it gives me nothing
     $data["company"] = $company;
     $this->load->view('admin/companyForm',$data);
}


here is my Model code

function getCompanyById($id) {


           $this->db->where('company_id',$id);
           $query = $this->db->get('companies');
           debug($query->row());/// it gives me object
           if ( $query->num_rows == 1 ) {
                 return $query->row();
           } else {
                 return false;
           }
}
Amjad Farooq,
Skype: shahgeb
cell: +923444553686
Reply
#2

(This post was last modified: 08-10-2015, 07:44 PM by pdthinh.)

(08-10-2015, 03:44 PM)shaheb Wrote: Hi, I am facing strange issue.

My model have a result from DB, when I debug it in model it gives me result but when I return it to controller it gives empty object. any suggestion ?

HERE is my Controller code

function editCompanyForm($companyId) {
      $this->load->model('Company');
      $company = $this->Company->getCompanyById($companyId);
      debug($company);exit; it gives me nothing
     $data["company"] = $company;
     $this->load->view('admin/companyForm',$data);
}


here is my Model code

function getCompanyById($id) {


           $this->db->where('company_id',$id);
           $query = $this->db->get('companies');
           debug($query->row());/// it gives me object
           if ( $query->num_rows == 1 ) {
                 return $query->row();
           } else {
                 return false;
           }
}

In your model code $query->num_rows() is a method. So it must be followed by parentheses.
Reply
#3

(This post was last modified: 08-11-2015, 09:39 AM by shaheb.)

thanks man, it solved, previously Ii was let me check like this.
Amjad Farooq,
Skype: shahgeb
cell: +923444553686
Reply




Theme © iAndrew 2016 - Forum software by © MyBB