How to initilize an array data while app started? |
[eluser]liren[/eluser]
Hello! I want to init an array data in memory when my webapp start.How to do it? If the autoloader could do it,please show my an example,thanks@!
[eluser]toopay[/eluser]
write a config file, for example 'myarray.php' then put into 'application/config', then you can write some array on it like... Code: <?php defined('BASEPATH') or die('No direct script access allowed'); Code: ... Code: var_dump($this->config->item('some_array'));
[eluser]liren[/eluser]
[quote author="toopay" date="1302260635"]write a config file, for example 'myarray.php' then put into 'application/config', then you can write some array on it like... Code: <?php defined('BASEPATH') or die('No direct script access allowed'); Code: ... Code: var_dump($this->config->item('some_array')); Thanks toopay: no,my config array is read from mysql database. when my webapp start,I want to app read database to memory,then I could using the config array anywhere in my webapp. How to do it?
[eluser]toopay[/eluser]
If you are about loading some data from database (not static resources like aboves), then want it available for any controller, you have several choice. 1. Make a "Base Controller" to load all necessary resource. Then other controller can use that resource by extending your "Base Controller". 2. As i said on your other thread, you can do that by configure some ‘pre_controller’ hook. Write a "Init" class which contain function to load your resource before all controller being called. 3. If you are want more clean and structural app, write some modules to handle that.
[eluser]liren[/eluser]
[quote author="toopay" date="1302263101"]If you are about loading some data from database (not static resources like aboves), then want it available for any controller, you have several choice. 1. Make a "Base Controller" to load all necessary resource. Then other controller can use that resource by extending your "Base Controller". 2. As i said on your other thread, you can do that by configure some ‘pre_controller’ hook. Write a "Init" class which contain function to load your resource before all controller being called. 3. If you are want more clean and structural app, write some modules to handle that.[/quote] If you are about loading some data from database (not static resources like aboves), then want it available for any controller, you have several choice. 1. Make a “Base Controller” to load all necessary resource. Then other controller can use that resource by extending your “Base Controller”. 2. As i said on your other thread, you can do that by configure some ‘pre_controller’ hook. Write a “Init” class which contain function to load your resource before all controller being called. 3. If you are want more clean and structural app, write some modules to handle that. The problem is: how to write a modules which build an array from database.then I could read and edit this array in my webapp? I open some autoload class,but when I restart apache server,the log don't output any initialize class log,like Log.php: Code: class CI_Session {
[eluser]toopay[/eluser]
Why i fell that in your case, 'pre_controller' hook is more than enough? You use module for something more sophisticated than that, like authentification stuff, templating stuff, etc.
[eluser]liren[/eluser]
[quote author="toopay" date="1302269493"]Why i fell that in your case, 'pre_controller' hook is more than enough? You use module for something more sophisticated than that, like authentification stuff, templating stuff, etc.[/quote] Do you mean that this array will be init when every user send a request to server? But I want to this array will be init only once when server start.
[eluser]InsiteFX[/eluser]
Code: $data = array(); InsiteFX
[eluser]liren[/eluser]
[quote author="toopay" date="1302270470"]There are no such things! Except you are using memcache, CI will send request to your database, everytime you load/init your resources.[/quote] Thank you toopay!I search many article in Google,find that you are right.it's not possible to do it in PHP,So sad |
Welcome Guest, Not a member yet? Register Sign In |