Search code examples
phpcakephpcakephp-2.x

How to get DATABASE_CONFIG value inside a plugin in cakephp?


I want to access the DATABASE_CONFIG class values located at app/config/database.php inside a plugin app/Plugin/Myplugin/bootstrap.php

class DATABASE_CONFIG {
    public $redis = array(
        'datasource' => 'Redis.RedisSource',
        'host' => '127.0.0.1',
        'port' => '6379',
        'db' => '2'
    );
}

I want to access the $redis host and port inside Myplugin

EDIT: THE CAKEPHP VERSION IS 2.1.2


Solution

  • Get the database details :-

    App::uses('ConnectionManager', 'Model');
    $dataSource = ConnectionManager::getDataSource('redis');
    $host = $dataSource->config['host'];
    $port = $dataSource->config['port'];