Welcome Guest, Not a member yet? Register   Sign In
write a configuration file dynamically
#1

[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...
#2

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

[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.
#4

[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.
#5

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

[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...
#7

[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.
#8

[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...
#9

[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!




Theme © iAndrew 2016 - Forum software by © MyBB