We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

About Phalcon\Config\Adapter\Ini

I've been searching in the docs, but I don't find a way to save changes to an INI file (offsetSet doesn't work), so I supposse I'll just have to use PHP ini functions, right?



5.4k
edited Feb '15

Once i was looking for same thing and not found it =( at my current project i'm using extended Config class with 2 additional functions:

...

public function toString(){
    $config = $this->toArray();
    $string = '; config [2.0]'."\n";
    foreach($config as $key => $option){
        if(is_array($option)){
            $string .= PHP_EOL.'['.$key.']'.PHP_EOL;
            $stringify = http_build_query($option);
            $stringify = str_replace(array('&', '%5B', '%5D', '=', '+'), array('"'.PHP_EOL, '.', '', ' = "', ' '), $stringify).'"';
            $stringify = rawurldecode($stringify).PHP_EOL;
            $string .= $stringify;
        }
        else{
            $string .= $key.' = "'.$option.'"'.PHP_EOL;
        }
    }

    return trim($string, PHP_EOL);
}

public function save($file){
    $file = new IO\Adapter\File($file);
    return $file->putContents($this->toString());
}

...

Not perfect, but i'm satisfied with it. Hope it can help you.



33.8k

I thank your effort, but I'm doing this just one time (for now). It's more quick using PHP functions directly.