Edit Codeigniter

Asked

Viewed 612 times

0

In the Codeigniter and I’m having a hard time loading into the customer’s form the data for him to change. The customer has to log in to the registration part and update their data. When it logs directly into the form for it to change and has the side menus with other data to change.

Appears the following error:

Severity: Notice

Message: Trying to get Property of non-object

Filename: views/cadastre.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();
}
  • Put the file code views/cadastro.php and point to the line 225 where the error is. A notice is saying that there is a reference to a non-existent object on the page. You have to find out if the object exists and is being passed correctly.

  • how you store the session $this->session->userdata('igrejas') that is to say igrejas? put that in your question, they’re saying there’s no such thing ->id may be up to a ['id'], so that item is missing!

1 answer

0

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

This is a common error that happens when trying to access properties in an array. The statement result() returns an array. The array has indexes. When you want just 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();
}

To documentation make it clear, take a look to clarify

Browser other questions tagged

You are not signed in. Login or sign up in order to post.