All the designers of the Codeigniter library expect one argument: an array of parameters, which is usually passed when the class is loaded with the CI loader, as in your example:
$params = array('type' => 'large', 'color' => 'red'); $this->load->library('Someclass', $params);
I assume you are confused about the "Do something with $ params" part. You do not need to pass any parameters, but if you do, you can use them as follows:
class Someclass { public $color = 'blue'; //default color public $size = 'small'; //default size public function __construct($params) { foreach ($params as $property => $value) { $this->$property = $value; } // Size is now "large", color is "red" } }
You can always reinitialize later if you need:
$this->load->library('Someclass'); $this->Someclass->__construct($params);
One more note: if you have a configuration file that matches the name of your class, this configuration will load automatically. For example, if you have a file application/config/someclass.php :
$config['size'] = 'medium'; $config['color'] = 'green';
This configuration will be automatically passed to the constructor of the "someclass" class when it is loaded.
source share