How do I connect to Cloudant using Sag in my Symfony 2 project?
Asked
Active
Viewed 182 times
1 Answers
3
- Configure Cloudant (create DB, API keys, etc.).
Add the following configuration to
app/config/parameters.yml.dist
:cloudant_hostname: ~ cloudant_port: 443 cloudant_use_ssl: true cloudant_database: ~ cloudant_username: ~ cloudant_password: ~
- If preferred, you can specify default values instead of "
~
".
- If preferred, you can specify default values instead of "
Install sag:
> composer.phar require "sag/sag":"dev-master"
- At the end of this step, Composer will prompt you to enter values for the parameters listed above.
Define the service in your bundle's
services.yml
file:services: cloudant: class: Sag arguments: - "%cloudant_hostname%" - "%cloudant_port%" calls: - [useSSL, ["%cloudant_use_ssl%"]] - [setDatabase, ["%cloudant_database%"]] - [login, ["%cloudant_username%", "%cloudant_password%"]]
Access the service in your controller:
/** @var \Sag $sag */ $sag = $this->get('cloudant'); /* You're now good to go! */ $post = $sag->get('postID')->body;