将EasyPost与cakephp集成

时间:2013-11-15 04:57:31

标签: php cakephp cakephp-2.0 shipping easypost

尝试整合这个: https://github.com/EasyPost/easypost-php

当我运行此代码时,我收到一条错误,指出Cake无法找到类地址。它实际上是加载了address.php文件,但由于某种原因它无法访问该类。我做错了什么?

  $address_params = array("name" => "Sawyer Bateman",
            "street1" => "388 Townasend St",
            //"street2" => "Apt 20",
            "city" => "San Francisco",
            "state" => "CA",
            "zip" => "94107",
            "country" => "US");

        $address = Address::create($address_params);
        $debug($address);

EasyPost.Easypost

 App::uses('EasyPostAppModel', 'EasyPost.Model');
 class EasyPost extends EasyPostAppModel {

 public $name = 'EasyPost';
 public $useTable = false;
 public static $apiKey;
 public static $apiBase = 'https://api.easypost.com/v2';
 public static $apiVersion = "2";

const VERSION = '2.0.7';

public static function getApiKey() {
    return self::$apiKey;
}

public static function setApiKey($apiKey) {
    self::$apiKey = $apiKey;
}

public static function getApiBase() {
    return self::$apiBase;
}

public static function setApiBase($apiBase) {
    self::$apiBase = $apiBase;
}

public static function getApiVersion() {
    return self::$apiVersion;
}

public static function setApiVersion($apiVersion) {
    self::$apiVersion = $apiVersion;
}

    public function __construct() {
        parent::__construct();
        EasyPost::setApiKey(XXX);

        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Util.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Error.php');

        // Guts
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Object.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Resource.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Requestor.php');

        // API Resources

        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Address.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/ScanForm.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/CustomsItem.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/CustomsInfo.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Parcel.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Rate.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/PostageLabel.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Shipment.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Refund.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Batch.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Tracker.php');
        require(App::pluginPath('EasyPost') . 'Lib/EasyPost/Event.php');



}

1 个答案:

答案 0 :(得分:2)

这个问题与CakePHP无关,你只是错过了EasyPost类所在的Address namespace(假设你在这里显示的代码实际上已经执行了 之后包含了类文件):

$address = \EasyPost\Address::create($address_params);