2015-11-30 56 views
0

我正在使用cakephp 2.6.7。我想將Authorize Api(http://www.authorize.net/)集成到我的cakephp應用程序中。我在本地主機中通過作曲家設置了api。它工作正常。這裏是文件結構: enter image description here如何在cakephp中使用授權API?

這裏charge-credit-card.php是最後一個運行腳本。在這個文件中我有一些預先必要文件如下:

require 'authorize/autoload.php'; 
use net\authorize\api\contract\v1 as AnetAPI; 
use net\authorize\api\controller as AnetController; 

現在我把授權文件夾內供應商的CakePHP的文件夾: enter image description here

而且我在paymentsController.php添加autoload.php爲如下:

require_once(APP . 'Vendor' . DS . 'authorize' . DS . 'autoload.php'); 

但我感到困惑

use net\authorize\api\contract\v1 as AnetAPI; 
use net\authorize\api\controller as AnetController; 

替換。我應該如何替換cakephp控制器中的這兩行?這裏是我的完整代碼:

<?php 

require_once(APP . 'Vendor' . DS . 'authorize' . DS . 'autoload.php'); 

use net\authorize\api\contract\v1 as AnetAPI; 
use net\authorize\api\controller as AnetController; 

define("AUTHORIZENET_LOG_FILE", "phplog"); 

class PaymentsController extends AppController { 

    var $layout = 'admin'; 

    // public $components = array('Auth'); 
    public function isAuthorized($user = null) { 
     $sidebar = $user['Role']['name']; 
     $this->set(compact('sidebar')); 
     return true; 
    } 

    public function beforeFilter() { 
     parent::beforeFilter(); 
     // Allow users to register and logout. 
     $this->Auth->allow('process'); 
    } 

} 

?> 

感謝您的時間。

+0

你能分享你得到的這個錯誤嗎? – KiKMak

回答

1

我想你的問題是特定於PHP別名而不是ANet SDK本身?

下面是關於製作全球可訪問的別名的問題。看起來,沒有簡單的方法。 PHP Global namespace aliases

相關: http://grokbase.com/t/php/php-general/10a38hape9/is-it-possible-to-create-a-global-namespace-alias


的默認方法是定義...

use net\authorize\api\contract\v1 as AnetAPI; 
use net\authorize\api\controller as AnetController; 

......在每個地方,你需要使用的別名文件。 (正如你必須知道的,一旦自動加載,命名空間是全局訪問的)

這應該有你的應用程序工作。