2013-07-22 20 views
1

我正在使用Stripe的PHP庫。 DL鏈接:https://code.stripe.com/stripe-php-latest.zipCodeIgniter - 爲什麼圖書館加載罰款的意見,但不是在控制器

我已經包括像這樣的內部視圖的庫: require_once(APPPATH.'libraries/stripe/lib/stripe.php');

一切正常,我這樣做是在一個視圖時,但如果我試圖做一個控制器,我得到服務器錯誤。爲什麼?

我試過codeigniters加載庫的方法,但仍然是服務器錯誤。我已經把所有的首都都改成了小箱子,還是錯誤的。

+0

嘿kolby m也面臨着同樣的問題。你能解決這個問題嗎? – geek2geek

回答

-1

嘗試將你的庫放在應用程序/庫上,然後加載你的庫管理器,其中包含 $ this-> load-> libraries('Stripe.php');

+0

服務器錯誤。 = \ – Kolby

+0

對不起,錯誤的方法名稱:$ this-> load-> library('class_name') –

+0

仍然是服務器錯誤。 – Kolby

1

如果使用THIRD_PARTY庫,例如像Facebook的PHP SDK,使用下面的代碼:

$this->_obj->load->add_package_path(APPPATH.'third_party/facebook/'); 
$this->_obj->load->library('facebook', $config);  
$this->_obj->load->remove_package_path(APPPATH.'third_party/facebook/'); 

並將文件放在t他的圖書館在/third_party/facebook/libraries/文件夾中。

注意:將文件直接放在'/ facebook /'而不是放在'/ libraries /'(在文檔中也沒有提到,太糟糕了)是常見的錯誤。

0

您可以通過添加codeigniter helper來使用條紋本機庫。

步驟1:將條紋包入輔助目錄

步驟2:重命名的init.php到init_helper.php

步驟3:輔助加載到控制器

$this->load->helper('stripe/init'); 

第4步:通話條紋庫

try 
{ 
    // set api key 
    \Stripe\Stripe::setApiKey('YOUR_SECRET_STRIPE_API_KEY'); 

    // create customer 
    $customer_detail = \Stripe\customer::create(array(
         'email' => '[email protected]' 
        )); 

    echo $customer_detail->id; 
} 
catch (Exception $e) 
{ 
    $error = $e->getMessage(); 
    echo $error; 
} 
相關問題