CodeIgniter Forums
Can't call a function defined in library folder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Can't call a function defined in library folder (/showthread.php?tid=49116)



Can't call a function defined in library folder - El Forum - 02-08-2012

[eluser]qpixo[/eluser]
I'm trying to call a function defined in a library folder. I'm calling in my Controller class. Some for reason, it doesn't go through this method calling. Can't get the echo display.

Does CI blocks any custom file defined on this folder? Any ways to fix that?

Code:
class Test extends CI_Controller {

// Constructor
function __construct() {
  
  parent::__construct();
  
  $this->load->library('tank_auth_groups', '', 'tank_auth');
}


public function index() {
  if(!$this->tank_auth->is_groups()) {
   echo 'get is_groups';
  }
}
}


Code:
class Tank_auth_groups extends Tank_auth {

// Constructor
function __construct() {
  
  parent::__contruct();
  
  $CI =& get_instance();
  $CI->load->model('tank_auth/ta_groups_users', 'users');
}

function is_groups() {
  return $CI->session->userdata('group_id') === '500';
}
}



Can't call a function defined in library folder - El Forum - 02-08-2012

[eluser]CroNiX[/eluser]
For one thing, It looks like $CI is undefined in is_groups() as you defined it in the __construct() as a local variable.


Can't call a function defined in library folder - El Forum - 02-09-2012

[eluser]qpixo[/eluser]
I made some change as global, still not working. What do I miss?

Code:
class Tank_auth_groups extends Tank_auth {

  private $CI;

// Constructor
function __construct() {
  
  parent::__contruct();
  
  $this->CI =& get_instance();
  $this->CI->load->model('tank_auth/ta_groups_users', 'users');
}

function is_groups() {
  return $this->CI->session->userdata('group_id') === '500';
}
}



Can't call a function defined in library folder - El Forum - 02-09-2012

[eluser]CroNiX[/eluser]
Are you manually loading Tank_auth somewhere? CI will only automatically load class extensions that start with the MY_ prefix. You probably need to create an __autoload() magic method to do this.

See here.

Also, is the group_id '500' a string or an int? If it's an int your check in is_groups() will always return false because you are using === which also checks the datatype.


Can't call a function defined in library folder - El Forum - 02-09-2012

[eluser]qpixo[/eluser]
[quote author="CroNiX" date="1328808249"]Are you manually loading Tank_auth somewhere? CI will only automatically load class extensions that start with the MY_ prefix. You probably need to create an __autoload() magic method to do this.

See here.

Also, is the group_id '500' a string or an int? If it's an int your check in is_groups() will always return false because you are using === which also checks the datatype.[/quote]

Noticed I have written in my controller above

This line is my controller is supposed to load tank_auth_groups which is extended by tank_auth

Code:
$this->load->library('tank_auth_groups', '', 'tank_auth');
...

then I have a condition in my index()

'500' is a string NOT an integer


Can't call a function defined in library folder - El Forum - 02-09-2012

[eluser]CroNiX[/eluser]
Yes, I saw that. That line loads tank_auth_groups and lets you access it by using tank_auth (instantiated as tank_auth). What I am saying is that CI won't automatically load tank_auth when you load tank_auth_groups, even though tank_auth_groups is extending tank_auth, so I was asking if you are manually loading it somewhere.


Can't call a function defined in library folder - El Forum - 02-09-2012

[eluser]qpixo[/eluser]
[quote author="CroNiX" date="1328815879"]Yes, I saw that. That line loads tank_auth_groups and lets you access it by using tank_auth (instantiated as tank_auth). What I am saying is that CI won't automatically load tank_auth when you load tank_auth_groups, even though tank_auth_groups is extending tank_auth, so I was asking if you are manually loading it somewhere.[/quote]


the tank_auth is manually load on its own constructor