开发者

Double Quote Problem after Saving an INI file with Zend_Config

I got a problem when I want to write and save an INI file. I use Zend_Config_Ini to handle this procedure.

The problem is I always got 'Double Quote' in the value for every line that use integer or number afer saving process. Here is the example

The original application.ini file

resources.session.use_only_cookies = 1
resources.session.remember_me_seconds = 86400

After I run these lines of code

$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini',
                                      null,
                                      array('skipExtends'        => true,
                                            'allowModifications' => true));

        // Modify a value
$config->production->resources->db->adapter = 'foobar';

        // Write the config file
$writer = new Zend_Config_Writer_Ini(array('config' => $config,
                                           'filename' => APPLICATION_PATH . '/configs/application.ini'));
$writer->write();

The application.ini lines become

resources.session.use_only_cookies = "1"  //double quote appears T_T
resources.session.remember_me_seconds = "86400"  //double quote appears T_T

What 开发者_开发知识库I want is the integer value must still remain the same (without double quotes).

Anyone can help me to solve this problem?

Thank you very much in advance


As Phil-Brown notes, when reading an ini file in PHP using parse_ini_file(), you always get strings back. Also, for for any value that isn't alphanumeric characters only, you should encase in double quotes, so Zend_Config_Writer encases all values.


Anyway,

In my solution, I had to remove some lines of code in Zend. The file that I changed was \Zend\Config\Writer\Ini.php for method _prepareValue() in line 150 to be like below

   protected function _prepareValue($value)
    {
        /*
         I comment it             

         if (is_integer($value) || is_float($value)) {
            return $value;
        } elseif (is_bool($value)) {
            return ($value ? 'true' : 'false');
        } else {
            return '"' . addslashes($value) .  '"';
        }*/

        return $value; // my line
    }

just comment the original code of Zend and just pass and return $value.

So, by changing this file I never get any double quote anymore for string, boolean or even number. This is that what I want. :)

Thank you everyone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜