Tuesday, 1 September 2009

Zend framework pull information from the application.ini

Zend framework pull information from the application.ini i used it to store the facebook info.

As i have a testing environment and a development one. I needed it to be in the wonderful application.ini where i can easily change between environments.

In the application.ini I have.

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1


resources.db.adapter = "mysqli"
resources.db.params.host = "localhost"
resources.db.params.username = "dbuser"
resources.db.params.password = "########"
resources.db.params.dbname = "########"

facebook.apikey = ########23415733; (NOTICE should be integer)

facebook.secret = ########66491221; (NOTICE should be integer)

[development : production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

resources.db.adapter = "mysqli"
resources.db.params.host = "localhost"
resources.db.params.username = ""########"
resources.db.params.password = ""########""
resources.db.params.dbname = "########"


facebook.apikey = ########2341577d; (NOTICE should be integer)
facebook.secret = ########6649128; (NOTICE should be integer)
Now i want in the bootstrap to initialize the facebook object.

$aConfig = $this->getOptions();
require_once(APPLICATION_PATH .'/../library/facebook-platform/php/facebook.php');
$facebook = new Facebook($aConfig['facebook']['apikey'],$aConfig['facebook']['secret']);
Zend_Registry::set('facebook', $facebook); // register the object .

Now i can use in my application like so.

$facebook = Zend_Registry::get('facebook');

Take care,

1 comments:

  1. Great article. I saw a few other methods posted online for using the application.ini and facebook API but yours was probably the most logically laid out and easiest to understand. Thanks!

    ReplyDelete