Welcome Guest, Not a member yet? Register   Sign In
Can't call a function defined in library folder
#1

[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';
}
}
#2

[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.
#3

[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';
}
}
#4

[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.
#5

[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
#6

[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.
#7

[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





Theme © iAndrew 2016 - Forum software by © MyBB