Welcome Guest, Not a member yet? Register   Sign In
How to disable the auto instantiate in Models or libraries
#1

[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?
#2

[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.
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB