EllisLab text mark
Advanced Search
     
function exists
Posted: 20 June 2008 04:48 AM
Avatar
Joined: 2008-04-06
142 posts

how can i check if function exists in CI

i did

if(function_exists($this->direction)) 

also,

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

 Signature 

CodeFight CMS - based on CI 2.0 | Facebook | All CI CMS | twitter | CI | My Website

 
Posted: 20 June 2008 05:13 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-18
120 posts

For checking if a particular method exists in some object, try to use method_exists() function:


http://php.net/method_exists

 
Posted: 20 June 2008 05:14 AM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-08-18
29 posts

Yes, you could try

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

 Signature 

Amatuer

 
Posted: 20 June 2008 05:28 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-04-06
142 posts

Thanks it worked

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

 Signature 

CodeFight CMS - based on CI 2.0 | Facebook | All CI CMS | twitter | CI | My Website