1

试图整合这个: 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);

易邮易邮

 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');



}
4

1 回答 1

2

该问题与 CakePHP 无关,您只是缺少类所在的EasyPost 命名空间Address(假设您在此处显示的代码实际上是在包含类文件之后执行的):

$address = \EasyPost\Address::create($address_params);
于 2013-11-15T11:56:17.893 回答