SmOg3R
SmOg3R

Reputation: 294

CodeIgniter - calling method from a variable

Let's keep it simple. We have this:

public function db($method)
    {   
        $this->$method.'()';
    }

I'am sure this is pretty self explanatory. Basically I want all my methods to be called trough this method 'db', but this is the error:

Message: Undefined property: site::$db

Ehm...

I guess I could write all the possible cases by hand, but is it really necessary??

Upvotes: 2

Views: 29

Answers (1)

haseeb
haseeb

Reputation: 682

Did you tried call_user_func($function); Or

$this->$function()

Or

$this->{$function}()

Upvotes: 1

Related Questions