Welcome Guest, Not a member yet? Register   Sign In
autoload models file => identifyer
#1

[eluser]domainsvault[/eluser]
is it possible to in the autoload.php to load models like I would in a controller.

In the autoload.php
you have:

$autoload['model'] = array('model1', 'model2');

In a controller I can do:
$this->load->model('model1', 'm1');

where I can reference m1 instead of model1. I think I tried this one time prior and failed, and now I find myself wanting to do it again cause I keep adding more modules to my system as I go and having to go through my controllers each time to do the same thing is a grueling task sometimes. So I would rather autoload the ones I am now with the same identifiers as the code already has and be able to move on from there on in without having to go back over all my code else where to adjust things.
#2

[eluser]John_Betong_002[/eluser]
If you have numerous models then I would be tempted to load the relevant model associated with the specific controller. Also just use the autoload.php to load and common models.

Code:
// controller
class C_specific extends MY_Application
{

//===================================================
function __construct()
{
  parent::__construct();
  $this->load->model('m_specific');

}

function index()
{
  // both m_application (autoloaded) and m_specific models are available

}
 
 
#3

[eluser]domainsvault[/eluser]
I do have a fair amount of models that would fall under common. But I am always refining stuff where I might want to add one or remove one and combine it with another its still early development. But what I wanted to try to avoid was having to go through all the controllers each time and alter the models per per controller, I figured it might be easier to auto load them, but in a sense where I can give it a custom identifier like I can if i load it into the controller.
#4

[eluser]John_Betong_002[/eluser]
I think that you should ideally adopt the technique I suggested"

1. autoload m_application common model
2. have one m_specific model allocated for each controller loaded in __constructor()

As you mentioned about "always refining stuff" aim to have unique model functions. ie if the m_specific->get_data() is called from another controller then it should be transferred to your m_application model.

Similarly if a m_application->get_data() is only used once then it should be moved to m_specific->get_data() function.

I think if you plan towards this way of working then it should cater for the majority of cases and any odd-ball functions to be moved to the m_application model.
 
 
 
edit:
My reasoning behind adopting the specified approach is to reduce the unnecessary loading (memory grabbing) modules which are not used.
 
 
 




Theme © iAndrew 2016 - Forum software by © MyBB