Fatal error: Call to a Member Function ola() on a non-object

Asked

Viewed 73 times

3

I need to use libraries in Codeigniter version 2.1.4 and I have problems using these libraries myself. After loading the library (with $this->load->library('Nomedabiblioteca'); in my controller), I have the line of code:

$a = $this->Nomedabiblioteca->teste();

To receive the return of the method teste() of the class. However, in this code line, controller returns the following error:

"Call to a Member Function test() on a non-object".

How can I resolve this situation? What am I doing wrong?

The library code is as follows (code for testing):

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Nomedabiblioteca{
    public function teste(){
        $a = 'algo';
        return $a;
    }
}
  • Your code is $a = $this->Nomedabiblioteca->teste(); or "$a = $this->Nomedabiblioteca->teste();"?

  • Use the function var_dump to check the property Nomedabiblioteca: var_dump($this->Nomedabiblioteca);

  • the code is $a = $this->Pathname->test();

  • var_dump returns null in the property. Undefined Property

1 answer

1

I managed to solve by changing the name of the class of

$a = $this->Nomedabiblioteca->teste(); //Capitalizada

To

$a = $this->nomedabiblioteca->teste();

It seems that codeigniter does not work for Ibraries in the same way as for controllers, models and views.

Browser other questions tagged

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