• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling a function in a library

#1
[eluser]stef25[/eluser]
How do I call a function in a library from another function in that same library? I have my $CI =& get_instance(); and the function I want to call is say test(). Ive tried calling it via test(), $this->test(), $CI->test(), $CI->lib_name->test() ...

?

#2
[eluser]danmontgomery[/eluser]
Code:
$this->test();

#3
[eluser]stef25[/eluser]
That gives a Call to undefined function error.

#4
[eluser]danmontgomery[/eluser]
Then you're doing something else wrong, post some code.

#5
[eluser]stef25[/eluser]
Code:
class my_lib {
    
function get_locations($location, $filter_array){
...
$nbr_matches = $this->count_key($test, 'full-name');
...
}

function count_key($array, $key) {
  $count = 0;
  foreach($array as $k => $val) {
    if($k == $key)
    $count++;
    if(is_array($val))
    $count += count_key($val, $key);
  }
  return $count;
  }
}

#6
[eluser]danmontgomery[/eluser]
Code:
$count += count_key($val, $key);
Should be
Code:
$count += $this->count_key($val, $key);

#7
[eluser]stef25[/eluser]
Great catch, thanks. I was looking at the wrong line number.

#8
[eluser]danmontgomery[/eluser]
Wink Cheers


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.