Welcome Guest, Not a member yet? Register   Sign In
why does loading the library also initializes the constructor?

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:
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...
...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:
$formObject = new MyFormObjects('the_name','text');
Any ideas?

I would think the solution to your problem is to include your class the standard php way...
or put it into the plugin folder

Are plug-ins loaded as classes? Seems like they're loading like simple functions, not classes.

loading a plugin is like if you include() a file
but you donĀ“t have to care about the path
(but the file has to be in the plugin folder with _pi.php as suffix

Theme © iAndrew 2016 - Forum software by © MyBB