Edit Codeigniter

0

In CodeIgniter and I'm having a hard time loading the data for it to change on the client form. The customer has to enter with his login in the part of cadastre and update his data. When he logs he goes straight into the form for it to change and has the side menus with other data to change.

The following error appears:

  

Severity: Notice

     

Message: Trying to get property of non-object

     

Filename: views / cadastro.php

     

Line Number: 225

Controller: Cadastrar.php

public function editar_cadastro($id) 
{
    if(null == $this->session->userdata('logado'))
    {
         $this->load->model('igrejas_model', 'igrejas');
         $this->db->where('id', $this->session->userdata('igrejas')->id);
         $data['cadastro'] = $this->igrejas->editar_cadastro($id);
         $this->load->view('cadastro', $data);
    }    
    else 
    {
         redirect (base_url("login"));
    }

}

Model: Igrejas_model.php

public function editar_cadastro($id=NULL) 
{
    $this->db->where('id',$id);
    $query = $this->db->get("igrejas");
    $return $query->result();
}
    
asked by anonymous 12.11.2016 / 15:17

1 answer

0

The problem is in this statement: $return $query->result();

This is a common error that happens when trying to access properties in an array. The result() statement returns an array. The array has indexes. When you want only one record, replace with row() .

Correct form:

public function editar_cadastro($id=NULL) 
{
  $this->db->where('id',$id);
  $query = $this->db->get("igrejas");
  return $query->row();
}

documentation makes this clear, take a look to clarify

    
21.11.2016 / 17:25