2

I am attempting to set-up multiple connections in my li3 project but when I do I get an uncaught exception. I set my connections in the app/confi/bootstrap/connections.php file which is then loaded in by the bootstrap.php file. Here is what I have for my connections:

 Connections::add('default', array(
    'development' => array(
            'type' => 'MongoDb',
            'host' => 'localhost',
            'database' => 'web_app'
    ),
    'test' => array(
        'type' => 'MongoDb',
        'host' => 'localhost',
        'database' => 'test_web_app'
    )
)
);

When I have it set like this and try to browse to my project I get this error:

 Fatal error: Uncaught exception 'lithium\core\ConfigException' with message 'No adapter set for configuration in class `lithium\data\Connections`.' in /var/www/site/libraries/lithium/core/Adaptable.php:233

However when I just have a single default connection set-up it works fine. Has anyone else ran into this issue?

--UPDATE-- I went looking through the stack trace from the exception and found the issue is caused by a filter I set-up in my file app/config/bootstrap/user.php which is then loaded by bootstrap.php

Here is what my user.php file looks like:

use app\models\Users;
use lithium\security\Password;

Users::applyFilter('save', function($self, $params, $chain) {
if ($params['data']) {
    $params['entity']->set($params['data']);
    $params['data'] = array();
}
if (!$params['entity']->exists()) {
    $params['entity']->password = Password::hash($params['entity']->password);
}
return $chain->next($self, $params, $chain);
});

According to the stack trace the error is coming from line 21 of this file. The only thing on line 21 is }); so I am still not certain why this is causing an error.

DMcP89
  • 705
  • 2
  • 10
  • 26

1 Answers1

1

It would appear I was mislead by Li3's Simple Authentication user tutorial. In their tutorial it has you create a user.php file in the bootstrap directory and has the filter logic in this file (Exactly what I had). However it seems this is not the best way to go about it, especially when using multiple connections as it will throw the exception above. I have moved the filter logic to my Users model file in app/models/Users.php and no longer get the exception. This is the same type of setup that Gavin Davies uses in his Li3 Authentication example.

DMcP89
  • 705
  • 2
  • 10
  • 26