• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function exists

#1
[eluser]dbashyal[/eluser]
how can i check if function exists in CI

i did
Code:
if(function_exists($this->direction))

also,
Code:
if(function_exists('direction'))

none of them worked

on the previous one it says undefined property direction

second one returns false

i searched the forum couldn't find the solution.

i am not that much into classes, so get hard time, sometimes

#2
[eluser]mironcho[/eluser]
For checking if a particular method exists in some object, try to use method_exists() function:


http://php.net/method_exists

#3
[eluser]Huan[/eluser]
Yes, you could try

if (method_exists($this->somename, some_function))

#4
[eluser]dbashyal[/eluser]
Thanks it worked

Code:
function _remap($method)
    {
        $method = str_replace('-', '_', $method);
        
        if (method_exists($this,$method)) {
            $this->$method();
        } else {
            $this->index();
        }
    }

may not be the best method that i am trying to do, but it still works. Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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