2012-06-06 69 views
6

我想將Google API包含在我的應用程序中。我想將Outh2 Key,Secret Key和Developer Keys定義爲常數,我可以在App控制器中調用和使用這些常量。CakePHP定義常量

哪個是最好的地方來定義相同的?

回答

9

/app/Config/bootstrap.php

我不會將它們設置爲常數,我會使用的配置類來存儲他們:

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

$key = Configure::read('outh2.key'); 
1

您可以宣佈類作品在供應商的谷歌API,那裏像往常一樣定義針常數。並且在您的應用控制器中僅包含如下供應商:

<?php 

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

class AppController extends Controller { 
...