tags:

views:

474

answers:

1

I have solved this problem, I just need to know what to do. I get the above error because I just realised that the class is being run as class::function($values) instead of class->function($values).

Does anyone know how to convert this function to instantiate the class then run the function with values?

private function _load($values=null) {

    define('LOADED_CONTROLLER', $this->controller);
    define('LOADED_FUNCTION', $this->function);

    $function = $this->function;

    $controller = new $this->controller;
    ($values == null) ? $controller->$function() : call_user_func_array(array($this->controller, $function), $values);
}
+3  A: 

You already instantiate the class:

$controller = new $this->controller;

Just use your $controller also in call_user_func_array:

($values == null) ? $controller->$function() : call_user_func_array(array($controller, $function), $values);

In your code you try to call a static method on the class if $value != null. That of course will result in an error if you use $this in this method.

Felix Kling
Sorry I don't understand. As I don't know the number of parameters I am using call_user_func_array. However when I do this I cannot use $this in my controller functions. Is there an alternative function?
JasonS
@JasonS: Of course you can do. But currently you are passing the class `array($this->controller, $function)` instead of the object `array($controller, $funtion)` to the function. That is where your error is.
Felix Kling
Ah ofcourse, I couldn't work out what had been changed. Thanks so much!
JasonS