CodeIgniter Forums
How to disable the auto instantiate in Models or libraries - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How to disable the auto instantiate in Models or libraries (/showthread.php?tid=7332)



How to disable the auto instantiate in Models or libraries - El Forum - 04-03-2008

[eluser]Diego Pessoa[/eluser]
Hi, I have a problem:

Code:
class Foo extends Model {
public $bar;

public function __construct($bar) {
parent::__construct();
$this->bar = $bar;
}

}

A simple classs right?

Let's to load this:

Code:
$this->load->model('Foo');

The result:
Message: Missing argument 1 for Foo.

How I can do to disable this auto-instantiate?


How to disable the auto instantiate in Models or libraries - El Forum - 04-03-2008

[eluser]wiredesignz[/eluser]
Not possible in CI, try a default value for the variable in the constructor

Code:
public function __construct($bar = NULL) {
    parent::Model();
    $this->bar = $bar;
}

Although, load_class('class_name', FALSE) is available, I haven't tried using this with Models.


How to disable the auto instantiate in Models or libraries - El Forum - 04-03-2008

[eluser]Diego Pessoa[/eluser]
Hummm, the load_class function solves the problem with libraries, but it not works with Models. =\