Welcome Guest, Not a member yet? Register   Sign In
Load libraries, database, models question
#1

[eluser]sn4k3[/eluser]
there are any problem

by calling for example: $this->load->database();
more than one time in same instance?

Thanks
#2

[eluser]heavenquake[/eluser]
Why do you want that? You can call it multiple times of you need a diferent database-groups like this:
Code:
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
But otherwise I can't see a reason for it.
#3

[eluser]sn4k3[/eluser]
no, not that i mean
im asking if there are a problem by calling $this->load->database(); multiple times
like you already call $this->load->database();, but you will load a model that calls $this->load->database(); too

There are any problem with that?
#4

[eluser]heavenquake[/eluser]
Ah. No problem, no. The CI loader usually returns immediately if the desired library/database/model is already loaded.

However, a best practice is to make sure you don't have multiple load->foo calls scattered all over your code. That way you reduce your debugging overhead when you want to deactivate a specific library -- the other way you risk it is still being loaded somewhere else that you've forgotten all about, and then you need to trawl through all of your code to find it (unless you know som grep tricks).

But it won't break your application if you accidentally load it multiple times, no. CI checks for you.
#5

[eluser]sn4k3[/eluser]
thanks for the information
#6

[eluser]AgentPhoenix[/eluser]
The other option would be to autoload the Database library so you don't run in to that issue and it's always available throughout your application.
#7

[eluser]heavenquake[/eluser]
[quote author="AgentPhoenix" date="1267124439"]The other option would be to autoload the Database library so you don't run in to that issue and it's always available throughout your application.[/quote]
That is indeed a highly possible solution. I however sense that the database was just an example, rather than the actual issue. Autoloading, say, the pages-model, would be unnecessary overhead on controllers that doesn't interact with pages. Also on high profile sites, you don't want to establish connections to the database unless you actually need it.




Theme © iAndrew 2016 - Forum software by © MyBB