Hobby99
Hobby99

Reputation: 703

When does it make sense to change a model name in Codeigniter

When calling a model in CI one has the option to change the model name in second parameter as follows:

$this->load->model('some_model', 'new_model_name');

I have seen it already but I do not understand the reason behind it - why would one would ever wanna do this. So my question is - When does it make sense to change a model name?

Upvotes: 0

Views: 365

Answers (2)

jmadsen
jmadsen

Reputation: 3675

Sometimes it is just to set more convenient names, but this can also help with dynamic code, such as outlined here:

http://codebyjeff.com/blog/2012/11/the-naming-of-things-writing-more-dynamic-code

In the example, models have the same functions but are mapped to different tables, and so this can allow you to slim down your code considerably.

Upvotes: 2

M Shahzad Khan
M Shahzad Khan

Reputation: 935

If you would like your model assigned to a different object name you can specify it via the second parameter of the loading function:

$this->load->model('Model_name', 'fubar');

$this->fubar->function();

http://ellislab.com/codeigniter%20/user-guide/general/models.html#loading

Upvotes: 0

Related Questions