[eluser]dedavai[/eluser]
It seems to me that CI initializes class constructors when it loads libraries with the $this->load->library method. Is there a way to initialize the class when creating new instances?
To clear it up, I'm writing a custom class/library that looks like this:
Code:
class MyFormObjects {
// class globals
public $formObject;
private $formTypes = array('text', 'pass', 'textarea', 'select', 'checkbox', 'radio');
public function MyFormObjects ()
{
// nothing here
}
public function __construct($name, $type, $value = '', $description = '', $rules = '')
{
if(!in_array($type, $this->formTypes, TRUE)) {
die("invalid type ($type)");
} else {
$this->formObject = array('name' => $name,
'type' => $type,
'value' => $value,
'description' => $description,
'rules' => $rules,
'validationError' => '');
}
}
When I try to load the library in my controller...
Code:
$this->load->library('MyFormObjects');
...I get an error because CI expects the $name and $type when loading the class. However, I want to be able to pass those variables during instance initialization, like this:
Code:
$formObject = new MyFormObjects('the_name','text');
Any ideas?