• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error: Unable to load the requested class

#1
Greetings,
I'm doing a web page project that is about printing shipping labels using PHP and easypost API. However I'm having trouble trying to load the library in the controller.

The client php library is on a folder called vendor and it looks like this
vendor/
composer
easypost/easypost-php/lib

Inside the lib folder it looks like this
EasyPost (folder)
cacert.pem
easypost.php

I moved the content inside the lib folder to the application library folder

So after that I tried to load the library in my Shipping.php controller
This is my construct inside shipping controller
PHP Code:
public function __construct() {
parent::__construct();
$this->load->helper('url''form');
$this->load->library('form_validation');

$this->load->library('EasyPost/easypost');



However i get an error
Unable to load the requested class: EasyPost

This is the EasyPost.php code
PHP Code:
<?php

namespace EasyPost;

abstract class 
EasyPost
{
 
   /**
     * @var string
     */
 
   public static $apiKey;

 
   /**
     * @var string
     */
 
   public static $apiBase 'https://api.easypost.com/v2';

 
   /**
     * @var string
     */
 
   public static $apiVersion "2";

 
   /**
     * Time in milliseconds to wait for a connection
     *
     * Zero or null means no timeout.
     *
     * @var int|null
     */
 
   public static $connectTimeout;

 
   /**
     * Time in milliseconds to wait for a response
     *
     * Zero or null means no timeout.
     *
     * @var int|null
     */
 
   public static $responseTimeout;

 
   /**
     * @var string
     */
 
   const VERSION '3.4.1';

 
   /**
     * get the API key
     *
     * @return string
     */
 
   public static function getApiKey()
 
   {
 
       return self::$apiKey;
 
   }

 
   /**
     * set the API key
     *
     * @param string $apiKey
     */
 
   public static function setApiKey($apiKey)
 
   {
 
       self::$apiKey $apiKey;
 
   }

 
   /**
     * get the API base URL
     *
     * @return string
     */
 
   public static function getApiBase()
 
   {
 
       return self::$apiBase;
 
   }

 
   /**
     * set the API base URL
     *
     * @param string $apiBase
     */
 
   public static function setApiBase($apiBase)
 
   {
 
       self::$apiBase $apiBase;
 
   }

 
   /**
     * get the API version
     *
     * @return string
     */
 
   public static function getApiVersion()
 
   {
 
       return self::$apiVersion;
 
   }

 
   /**
     * set the API version
     *
     * @param $apiVersion
     */
 
   public static function setApiVersion($apiVersion)
 
   {
 
       self::$apiVersion $apiVersion;
 
   }

 
   /**
     * Set time in milliseconds to wait for a connection
     *
     * Zero or null means no timeout.
     *
     * @return int|null
     */
 
   public static function getConnectTimeout()
 
   {
 
       return self::$connectTimeout;
 
   }

 
   /**
     * Get time in milliseconds to wait for a connection
     *
     * Zero or null means no timeout.
     *
     * @param int|null $connectTimeout
     */
 
   public static function setConnectTimeout($connectTimeout)
 
   {
 
       self::$connectTimeout $connectTimeout;
 
   }

 
   /**
     * Get time in milliseconds to wait for a response
     *
     * Zero or null means no timeout.
     *
     * @return int|null
     */
 
   public static function getResponseTimeout()
 
   {
 
       return self::$responseTimeout;
 
   }

 
   /**
     * Get time in milliseconds to wait for a response
     *
     * Zero or null means no timeout.
     *
     * @param int|null $responseTimeout
     */
 
   public static function setResponseTimeout($responseTimeout)
 
   {
 
       self::$responseTimeout $responseTimeout;
 
   }




the easypost.php that's not inside the EasyPost folder has this code
PHP Code:
<?php

// Require this file if you're not using composer's vendor/autoload

// Required PHP extensions
if (!function_exists('curl_init')) {
  throw new Exception('EasyPost needs the CURL PHP extension.');
}
if (!
function_exists('json_decode')) {
  throw new Exception('EasyPost needs the JSON PHP extension.');
}

// Config and Utilities
require(dirname(__FILE__) . '/EasyPost/EasyPost.php');
require(
dirname(__FILE__) . '/EasyPost/Util.php');
require(
dirname(__FILE__) . '/EasyPost/Error.php');

// Guts
require(dirname(__FILE__) . '/EasyPost/EasyPostObject.php');
require(
dirname(__FILE__) . '/EasyPost/EasypostResource.php');
require(
dirname(__FILE__) . '/EasyPost/Requestor.php');

// API Resources
require(dirname(__FILE__) . '/EasyPost/Address.php');
require(
dirname(__FILE__) . '/EasyPost/Batch.php');
require(
dirname(__FILE__) . '/EasyPost/CarrierAccount.php');
require(
dirname(__FILE__) . '/EasyPost/Container.php');
require(
dirname(__FILE__) . '/EasyPost/CustomsInfo.php');
require(
dirname(__FILE__) . '/EasyPost/CustomsItem.php');
require(
dirname(__FILE__) . '/EasyPost/Event.php');
require(
dirname(__FILE__) . '/EasyPost/Fee.php');
require(
dirname(__FILE__) . '/EasyPost/Item.php');
require(
dirname(__FILE__) . '/EasyPost/Order.php');
require(
dirname(__FILE__) . '/EasyPost/Parcel.php');
require(
dirname(__FILE__) . '/EasyPost/Pickup.php');
require(
dirname(__FILE__) . '/EasyPost/PostageLabel.php');
require(
dirname(__FILE__) . '/EasyPost/Rate.php');
require(
dirname(__FILE__) . '/EasyPost/Refund.php');
require(
dirname(__FILE__) . '/EasyPost/ScanForm.php');
require(
dirname(__FILE__) . '/EasyPost/Shipment.php');
require(
dirname(__FILE__) . '/EasyPost/Tracker.php');
require(
dirname(__FILE__) . '/EasyPost/User.php');
require(
dirname(__FILE__) . '/EasyPost/Insurance.php');
require(
dirname(__FILE__) . '/EasyPost/Report.php');
require(
dirname(__FILE__) . '/EasyPost/Webhook.php'); 
if i use require_once("application/vendor/easypost/easypost-php/lib/easypost.php");
then everything works fine. But to complete the project I'm required to load the library using codeigniter. 

So what am I doing wrong?
Reply

#2
@Kizaru,

What version of CI are you using? If you are using CI 3.x the library loader is expecting a class not a namespace. Check the forums for solutions that will allow you to use namespaces.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.