首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将EasyPost与cakephp集成

将EasyPost与cakephp集成
EN

Stack Overflow用户
提问于 2013-11-15 12:57:31
回答 1查看 381关注 0票数 1

尝试集成:https://github.com/EasyPost/easypost-php

当我运行这段代码时,我得到一个错误,说Cake找不到类地址。它实际上加载了address.php文件,但是由于某些原因它不能访问这个类。我做错了什么?

代码语言:javascript
复制
  $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

代码语言:javascript
复制
 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');



}
EN

回答 1

Stack Overflow用户

发布于 2013-11-15 19:56:18

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

代码语言:javascript
复制
$address = \EasyPost\Address::create($address_params);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19993818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档