CodeIgniter Forums
write a configuration file dynamically - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: write a configuration file dynamically (/showthread.php?tid=53890)



write a configuration file dynamically - El Forum - 08-13-2012

[eluser]sakcret[/eluser]
I need to write a configuration file dynamically, the file will create the folder config / miarchivoconfiguracion.php, define periods in the example:

Code:
$ config ['fecha_periodo_inicio'] = '2012-01-01 ';
$ config ['fecha_periodo_fin'] = '2012-10-30 ';

try $ this-> set_item ('fecha_periodo_inicio', '2012-02-01 ');
apparently does not work because not physically writes the file
anyone know how to do please hel me thanks...


write a configuration file dynamically - El Forum - 08-13-2012

[eluser]LonelyWolf[/eluser]
Seems a stupid question, but CI has write access to that folder?


write a configuration file dynamically - El Forum - 08-13-2012

[eluser]TWP Marketing[/eluser]
If this information is changing frequently, or changing at all, put it into a control file record and simply write to your database.


write a configuration file dynamically - El Forum - 08-13-2012

[eluser]InsiteFX[/eluser]
I just got done answering this in another topic.

CI does not save the values to the config file they are temporary value.



write a configuration file dynamically - El Forum - 08-13-2012

[eluser]ribe[/eluser]
Obviously, User Guide should mention that.


write a configuration file dynamically - El Forum - 08-14-2012

[eluser]sakcret[/eluser]
Thanks all, I found that only changes the value for the current request does not write the configuration file, I was confused because the manual says you can change set_item ('something', 'something'); currently use MAMP and sometimes I have trouble with it is handled by the compiled application, it was just a question I forgive you again with the framework, what I did was

Code:
function cambiaPeriodo() {
        $f1 = $this->input->post('fecha_inicio_r1');
        $f2 = $this->input->post('fecha_fin_r1');
        $nombre_fichero = 'application/config/configuracion_sistema.php';
        $contenido_config = $this->getContentfile($nombre_fichero);
        $fichero_texto = fopen($nombre_fichero, "w+");
        fclose($fichero_texto);
        $fecha_inicio = $this->config->item('fecha_periodo_inicio');
        $fecha_fin = $this->config->item('fecha_periodo_fin');
        $new_fecha_inicio = $this->utl_apecc->getSQL_date($f1);
        $new_fecha_fin = $this->utl_apecc->getSQL_date($f2);
        //obtener arreglos para buscar y rempazar variables
        $buscar_replace = array("['fecha_periodo_inicio']='$fecha_inicio';", "['fecha_periodo_fin']='$fecha_fin';");
        $replace = array("['fecha_periodo_inicio']='$new_fecha_inicio';", "['fecha_periodo_fin']='$new_fecha_fin';");
        //remplazar contenido
        $fp = fopen($nombre_fichero, "a");
        $nuevo_contenido = str_replace($buscar_replace, $replace, $contenido_config);
        fwrite($fp, $nuevo_contenido);
        fclose($fp);
    }

Sorry LonelyWolf stop by sometimes little things but ultimately affect greetings...


write a configuration file dynamically - El Forum - 08-14-2012

[eluser]CroNiX[/eluser]
[quote author="ribe" date="1344885719"]Obviously, User Guide should mention that.[/quote]Why should it mention what it doesn't do? Most docs I've ever read state what it WILL do and assume if it doesn't say it can do it that it can't.


write a configuration file dynamically - El Forum - 08-14-2012

[eluser]sakcret[/eluser]
I'm sorry you're right CroNiX needed a quick fix as it is for my school project, sorry could not assume that
i need document myself CI thanks...


write a configuration file dynamically - El Forum - 08-20-2012

[eluser]timmahoney[/eluser]
Hi All

I had a need for this a while ago, and made something to accommodate it. When I came across this post, I dug it up and put it on github.

CodeIgniter Dynamic System Configuration

Let me know what you think!