views:

73

answers:

2

I'm trying to implement a class I've written as CodeIgniter library.

Somehow I can't get CI's load() method to pass multiple arguments to the class's constructor function.

My class is designed to get 3 arguments, 2 arrays and one optional string.

The constructor looks somewhat like this:

public function __construct($array, $array,$string=""){
/** code **/
}

The relevant part from the controller:

function index(){
  $array1 = array('key1'=>'value','key2'=>'value');
  $array2 = array('key1'=>'value','key2'=>'value');
  $string = "value";
  $params = array($array1,$array2,$string);
  $this->load->library("MyClass",$params);
}

Loading the controller generates this error :

Message: Missing argument 2 for MyClass::__construct()

This is really puzzling me. It seems the first argument gets sent fine and then it chokes on the second argument. Any clues on why this is happening will be greatly appreciated.

A: 

you forgot the $ on array2 when declaring params, causing it be passed as a constant that isn't defined instead of an array.

GSto
Ups...just a typo. But thanks anyway :). Edited.
Andrei
A: 

You need to modify your class constructor to handle the passed data as described here:

http://codeigniter.com/user_guide/general/creating_libraries.html

public function __construct($params)
{
    $array1 = $params[0];
    $array2 = $params[1];
    $string = $params[2];

    // Rest of the code
}
spidEY
Thanks ! That was the problem. I had read trough the documentation but somehow skipped over that part :)
Andrei