CakePHP Defining Constants
Asked Answered
M

2

6

I want to include Google API in my app. I want to Define Outh2 Key, Secret Key and Developer Keys as Constants which i can call and use in the App controller.

Which is the best place to define the same ?

Mating answered 6/6, 2012 at 14:52 Comment(0)
S
9

/app/Config/bootstrap.php

I wouldn't set them up as constants, I'd use the configure class to store them:

Configure::write(array(
    'outh2.key'=>'foo',
    'outh2.secret_key'=>'bar',
    'outh2.dev_key'=>'baz'
));

$key = Configure::read('outh2.key');
Stratovision answered 6/6, 2012 at 15:34 Comment(1)
Why cant we use just define('CONSTANT_NAME','constant value')Dumortierite
R
1

You may announce class which works with google API in vendors, there you define needle constants as usual. And in your app controller only include vendor like this:

<?php

App::import('Vendor', 'google', array('file' => 'google.php'));

class AppController extends Controller { 
...
Rocha answered 6/6, 2012 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.