Call to a Member Function method() on string

Asked

Viewed 494 times

0

I am using Codeigniter and, while trying to do a search in my database to see if a given line really exists, it presents the error Call to a member function checarId() on string. Follow the code of the functions that return me this error:
Function in class Responsavel (the matricula is a varchar(20) in the BD):

    function checarId($mat){
        $cont = 0;
        $this->load->database();
        $query = $this->db->query('SELECT * FROM responsavel where matricula = '.$mat);
        foreach($query->result() as $row){
            $cont++;
        }
        if($cont == 1){
            return true;
        }else{
            return false;
        }
    }

Now follow the code of the function that calls the above function, already in the Room class to check whether or not you can add a line to the BD:

function salvar(){
    $data = array('nome' => $this->getNome(), 'codigoresponsavel' =>$this->getResponsavel());
    $this->load->model('responsavel');
    $this->load->database();
    $existe=$this->checarExistencia($this->getNome());

    $respExiste = $this->responsavel->checarId((string)$this->getResponsavel());

    if($existe && $respExiste){
            $this->db->where('nome', $this->getNome());
            $this->db->update('sala', $data);
    }else if($respExiste){ 
        /*$this->load->model('responsavel', 'resp');
        if($this->resp->checarId((string)$this->getResponsavel())){*/
            $this->db->insert('sala', $data);
        /*}
        else{
            $this->load->view('index');
        }*/
    }else{
        $this->load->view('index');
    }
}
  • Have you tried public function checarId($mat) ?

  • I hadn’t tried yet, I tried here and it didn’t help

  • What is your model’s file name?

  • The $this->getResponsavel() method actually returns a string?

No answers

Browser other questions tagged

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