Welcome Guest, Not a member yet? Register   Sign In
Model in CodeIgniter
#1

[eluser]Unknown[/eluser]
Why is this doesn't work ?


$this->dataModel = $this->load->model('Model_db');
$data = $this->dataModel->list(); -> failed


Does Model can't be assigned to a variable?
#2

[eluser]n0xie[/eluser]
Code:
$this->load->model('Model_db', 'dataModel');
$data = $this->dataModel->list();
#3

[eluser]welzai[/eluser]
i never use this way assigning a model in variable.

i always use such,

$this->load->model('Model_db','dataModel');
$data = $this->dataModel->list();

I hope I have helped
#4

[eluser]rogierb[/eluser]
You dont'need to assign it. It is loaded in the CI superobject. So you can reference the model class directly.

Code:
$this->load->model(‘Model_db’); // model get loaded into CI
$data = $this->Model_db->list(); // Calling method list() in the Model_DB class

If you want a different name:
Code:
$this->load->model(‘Model_db’, 'another_name'); // model get loaded into CI
$data = $this->another_name->list(); // Calling method list() in the Model_DB class

Edit: To late ;-)
#5

[eluser]LuckyFella73[/eluser]
Why don't you name your model like you would like to call in your controller?

Anyway the user guide says:
Quote:If you would like your model assigned to a different object name you can specify it via the second parameter of the loading function:
Code:
$this->load->model('Model_name', 'fubar');
$this->fubar->function();

I'm tooooo slow .....




Theme © iAndrew 2016 - Forum software by © MyBB