• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where store a lot of arrays?

#1
I have some collection of static arrays, that I need to use somewhere in my app - that are hundreds names, families, countries, that I`m using to generate some random data, or display in a view, or use in model for other needs. I`m not sure where to store these arrays. First I make a custom config file and put them there, but I don`t think is it the right place. Now, I`m using library class, but Im not sure that i propose of libraries.


PHP Code:
class Storage {

private 
$someArray = [...];

private 
$anotherArray = [...];

private 
$thirdArray = [...];

public function 
getArray($type
{
   $array $this->{$type};
   return $array;
}
 

Reply

#2
Why not store them in a database and call them as needed?

If you need say 10 random names from your hundreds of names, just do a query like the ones described here:
https://stackoverflow.com/questions/4329...-rows-fast
Reply

#3
Becouse is a static data that do no need to be in database. I have array that hold all my tactics, I use it in view - to make option menu, I used in my Engine to grab some data related to each tactic, I used in controller to inject the models. This is like a config data, but a bit more...
Reply

#4
Then in my opinion both methods you have used are fine. I think I would use libraries and config files. In your library load the config files you need for each function (unless you always need all of them all the time) then creating added functionality like getting a single name, family and country for a profile, you can easily build it in. Having the data in separate config files is clean too, keeping the large static arrays out of the libraries.
Reply

#5
Both. Use separate configuration files to put your data and then create a library (it could be a model too, $this conveniently behaves there in a similar way as in controllers) that is to read the configuration files within their methods or, if necessary within the constructor. While reading this specific configuration use the "section" parameter for not making a possible conflict with the existing common configuration. Then in your application use only the library (or the model), it will "know" where to read data from, writing code would be easy.
Reply

#6
if I have static data i usually keep it under config dir, but in your case if you have a large set then you might as well create a directory under application called data and put it there.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.