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

Phalcon YAML Config

Can't get this YAML config adapter to work. I've tried;

Tried this: https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Config/Adapter

Getting error: BadMethodCallException: Wrong number of parameters /pub/index.php (33)

Tried this: https://api.phalcon.io/en/1.3.3/Phalcon/Config/Adapter/Yaml

Completely empty.

Any ideas on how to use YAML in v1.3.4 ? Between JSON works. Thanks.



507

Please make sure yaml pecl extension is installed. Following steps for ubuntu installation to do so:

  • sudo apt-get install libyaml-dev
  • sudo pecl install yaml
  • Add extension=yaml.so to your /etc/php5/fpm/php.ini (or put it into appropriate extension file)
  • Restart PHP


16.6k
edited Jan '15

It was php-yaml (aur) package in Arch Linux. But I still get this error;

BadMethodCallException: Wrong number of parameters

When using this example code;

define('APPROOT', dirname(__DIR__));
define('CONFKEY', 'secret');

$config = new Phalcon\Config\Adapter\Yaml('test.yaml', 
    array(
        '!decrypt' => function($value) {
            return (new Phalcon\Crypt)->setCipher('blowfish')->decryptBase64($value, CONFKEY);
        },
        '!approot' => function($value) {
            return APPROOT . $value;
        }
    )
);

echo $config->phalcon->controllersDir;
echo $config->database->username;
echo $config->database->password;


507

Sorry, I'm using Phalcon2 right now and cannot test it on lower version. Following code works for me perfectly:

        $config = new \Phalcon\Config\Adapter\Yaml('/tmp/test.yaml',
            array(
                '!decrypt' => function($value) {
                    return (new \Phalcon\Crypt)->setCipher('blowfish')->decryptBase64($value, CONFKEY);
                },
                '!approot' => function($value) {
                    return APPROOT . $value;
                }
            )
        );

Install yaml extension