首页 > 解决方案 > 如何在 codeigniter 中包含和使用自己的类(来自插件)

问题描述

我想将插件中的一个类使用到我的codeigniter中,然后使用到我的控制器和模型中

这是我想要包含和使用的课程的一部分

<?php 
//start of https://github.com/repat/plentymarkets-rest-client
namespace repat\PlentymarketsRestClient;

use Carbon\Carbon;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
use Stringy\Stringy as s;

Class PlentymarketsRestClient extends CI_Controller{

    const PATH_LOGIN = 'rest/login';
    const METHOD_GET = 'GET';
    const METHOD_POST = 'POST';
    const METHOD_PUT = 'PUT';
    const METHOD_PATCH = 'PATCH';
    const METHOD_DELETE = 'DELETE';

    const THROTTLING_PREFIX_LONG_PERIOD = 'X-Plenty-Global-Long-Period';
    const THROTTLING_PREFIX_SHORT_PERIOD = 'X-Plenty-Global-Short-Period';
    const THROTTLING_PREFIX_ROUTE = 'X-Plenty-Route';

    private $client;
    private $config;
    private $configFile;
    private $rateLimitingEnabled = true;
    private $throttledOnLastRequest = false;

    public function __construct($configFile, $config = null)
    {
        $this->client = new Client();
        if ($config !== null) {
            $this->config = $config;
        } else {
            $this->config =  $this->readConfigFile($configFile);
        }
        ....

我如何在我的 codeigniter 项目中包含和使用它?

标签: phpcodeigniter

解决方案


有几种方法。这是一个简单的方法。我将以下代码添加到 Controller 的前面以尝试使用它。

require_once APPPATH . 'controllers/PlentymarketsRestClien.php'; 

class Dashboard extends PlentymarketsRestClien {
....
}

推荐阅读