- 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;
Connect Sag with Cloudant in Symfony2 project
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow