2013-03-15 97 views
1

我正在構建一個CodeIgniter 2.1.3應用程序,該應用程序將Twitter OAuth API用於多種功能。我將所有的Twitter API代碼放在一個單獨的文件app_tokens.php中,該文件被git忽略。我用什麼函數將這個文件包含在我的Tweet類中?CodeIgniter中的敏感數據

app_tokens.php:

<?php 
$consumer_key = 'xxxxxxxxxxxxxxxxxxxxxx'; 
$consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; 
$user_token = 'xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx'; 
$user_secret = 'xxxxxxxxxxxxxxxxxxxx'; 
?> 

謝謝!

+2

HTTP: //php.net/include? – 2013-03-15 21:59:20

+0

Pekka是正確的...一個簡單的谷歌搜索「包含PHP文件」將顯示一個.. – 2013-03-15 22:02:58

回答

2

application/config文件夾中創建一個名爲tweet.php文件,並把這個在它與你的真實過程的數據代替X的:

<?php 

$config['consumer_key'] = 'xxxxxxxxxxxxxxxxxxxxxx'; 
$config['consumer_secret'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; 
$config['user_token'] = 'xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx'; 
$config['user_secret'] = 'xxxxxxxxxxxxxxxxxxxx'; 

然後在您的資料Tweet類加載該配置文件通過這樣做:

$this->config->load('tweet'); 

然後你就可以訪問這些配置值,像這樣:

$this->config->item('consumer_key');