Welcome Guest, Not a member yet? Register   Sign In
Why the Undefined property
#1

[eluser]thefatladysingsopera[/eluser]
I have this library i have written

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

class Globel {

    public function le_gruqq()
    {
echo 'true';
    }
}

/* End of file Globel.php */

but when i call it inside my reports.php controller like

Code:
public function atone(){
echo $this->Globel->le_gruqq();
}

i get this error


Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Reports::$Globel

Filename: controllers/reports.php(3) : eval()'d code(1) : eval()'d code

Line Number: 15
Fatal error: Call to a member function le_gruqq() on a non-object in /var/www/html/ur/application/controllers/reports.php(3) : eval()'d code(1) : eval()'d code on line 15

I have loaded my library in the constructor the right way so i am not sure why calling a function in the library does not work.
#2

[eluser]CroNiX[/eluser]
Show where you are loading the library.
#3

[eluser]thefatladysingsopera[/eluser]
In here

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

class Reports extends CI_Controller {

public function __construct()
{
  parent::__construct();

  $this->load->library('Globel');
}
public function atone(){
echo $this->Globel->le_gruqq();
}
#4

[eluser]CroNiX[/eluser]
Hmm, that looks ok. Try using lower case "globel" when accessing the library. Maybe when loading it too. I never capitalize libraries/controllers or their methods.
#5

[eluser]thefatladysingsopera[/eluser]
No change.I still canot access the function atone() even when the library is globel.
#6

[eluser]RobertSF[/eluser]
It has to be lower case everywhere except in the class name.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Reports extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('globel');
}
public function atone(){
echo $this->globel->le_gruqq();
}

Then it works fine. Smile




Theme © iAndrew 2016 - Forum software by © MyBB