New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot get connection to work when using multiple keys for environments #1153
Comments
Most likely the environment is either not being specified, or is being specified after your application's first attempt to access the database. To verify, call For a proper implementation, see the docs for |
@nateabele Two things.
lithium\core\Environment::is(function($request){ if ($host == 'project.local' || $host == 'localhost') { in the library bootstrap file and it never seems to fire. It seems strange to me that without that code, the framework would return an empty string for the environment. Is this normal behavior or is something else misconfigured? |
@nateabele So a lot of this involves trying to run a test on my users controller, and it seems that even though the tests run now without the original error, it's still not behaving as expected. When I output Environment::get() in my setUp method in my controller test, it outputs "test". When I output the available connections, it shows default and test. When I output Connections::get("test") it shows the correct connection info, but when I run my actual test (to create a user and then to remove the user collection on tearDown) it operates on the default connection settings. I'm clearly doing something very wrong here, but based on documentation, I have no idea what more could be wrong. |
Look at the call trace, figure out where the call to the database is coming from, and, wherever the stack leaves your code and enters the framework, log to make sure the environment is correct. If the database works without an environment configuration, then this is the problem. |
Whenever I try to define multiple environments for my default connection, I get the following error:
PHP Fatal error: Uncaught exception 'lithium\core\ConfigException' with message 'No adapter set for configuration in class
lithium\\data\\Connections
My connection is defined as follows:
Connections::add('default', array(
'development' => array(
'type' => 'MongoDb',
'host' => 'localhost',
'database' => 'dev'
),
'test' => array(
'type' => 'MongoDb',
'host' => getenv("MONGO_IPADDRESS"),
'database' => 'test'
),
'production' => array(
'type' => 'MongoDb',
'host' => getenv("MONGO_IPADDRESS"),
'database' => $_SESSION['settings']->company_short
)
));
in my connections bootstrap file. I have tried for 2 weeks to get this to work and no matter what I do, unless I hardcode the environment in a bootstrap file, it always throws the above error. If I define one default connection (Connections::add('default', array('type'=>'MongoDb', 'host'=>'localhost', 'database'=>'blah') it works fine. I'm desperate for help.
The text was updated successfully, but these errors were encountered: