New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autoloader should support loading a model under a different name #2117
Comments
$autoload['model'] = array(array('users_model', 'users'), array('comments_model', 'comments'), 'auth_model'); Has to be .. $autoload['model'] = array('users_model'=> 'users', 'comments_model'=>'comments', 'auth_model'); |
Aha, silly me. Of course, that is simpler and nicer. Forgive me, it's 6 AM where I am. |
What about loading multiple models in the controller in such a fashion?
To be like so:
|
@dwightwatson The original poster is specifically talking about autoloading models, not doing so manually in the controller. |
@TheDigitalOrchard I am aware, but as far as the feature suggestion goes I think that mechanism of loading models with a custom name is needed by the loader outside of |
This should be relatively easy to do -- who's up for the challenge? |
I'll have a crack, but I'm not sure if CodeIgniter has a precedence for working out whether an array is sequential or associative.
Does anyone have any tips on this? |
I would use another level of arrays.
The individual arrays could then use key => value, or maybe two array items that can be |
That makes perfect sense, I've now made a pull request to the develop branch. |
There you go. |
I'm surprised this didn't get commited yet... |
It did: b07f700 |
CI_Loader::model() supports an optional second argument for renaming the model (cf. http://ellislab.com/codeigniter/user-guide/general/models.html#loading ). It should also be possible to provide a name when the model is autoloaded from $autoload['model'], e.g.,
$autoload['model'] = array(array('users_model', 'users'), array('comments_model', 'comments'), 'auth_model');
to load Users_model as "users", Comments_model as "comments", and Auth_model as "auth_model" (no optional name specified).
The text was updated successfully, but these errors were encountered: