How to autoload model / library witha different object name |
[eluser]Lone[/eluser]
Just curious if anyone could help me solve the following issue I am having. We need to autoload a model but am having double class naming issues with a controller that has the same class name. Usually in a controller you can just go as below to access as $this->User Code: $this->load->model('user_model','User); But when autoloading you are forced to have it name as $this->User_model when I want it as $this->User Code: //autoload.php I know I can change the model filename and class name to 'User' but when its autoloaded in a contoller with the same classname as 'User' you get the double naming error. Is there any easy way to achieve this without having to do the $this->load->model call in every controller construct - eg. back to autoloader?
[eluser]Pascal Kriete[/eluser]
I always have my own base controller off of which I extend others, so I would do: Code: class BaseController extends Controller { Of course you only have that luxury if you extend the ci controller.
[eluser]Lone[/eluser]
Nice idea there - but Im trying for no extra code in controllers to achieve this.
[eluser]Pascal Kriete[/eluser]
I would love to see a solution to this, but I don't think it's possible. For it to be accessible 'globally', it needs to be either auto-loaded or a global variable. The only widely available variables that are not in the super-object scope are those in the ci_controller.
[eluser]xwero[/eluser]
I think inparos solution is the only one for renaming a model that is autoloaded without hacking CI.
[eluser]Lone[/eluser]
Well what this is ideally needing is the ability to do an associative array for the autoloader eg. Code: $autoload['model'] = array( Maybe I should put as a feature request? But for in the meantime I need to sort out a solution - I have been think a lil bit dirty by having a 'base model' and loading them like below.. Code: $autoload['model'] = array('base_model'); Havent tried it but guessing will work in theory - just a lil dirty for my liking.
[eluser]Lone[/eluser]
Ok I have made a feature request to cover this issue and resolve by allowing assoc arrays. http://ellislab.com/forums/viewthread/72858/ Interestingly enough I have found that Matchbox already does this in a similar way
[eluser]wiredesignz[/eluser]
Code: <shameless_plug> |
Welcome Guest, Not a member yet? Register Sign In |