尝试集成: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');
}发布于 2013-11-15 19:56:18
问题与CakePHP无关,您只是缺少Address类所在的EasyPost namespace (假设此处显示的代码实际上是在包含类文件之后执行的):
$address = \EasyPost\Address::create($address_params);https://stackoverflow.com/questions/19993818
复制相似问题