php - 如何在 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 项目中包含和使用它?
解决方案
有几种方法。这是一个简单的方法。我将以下代码添加到 Controller 的前面以尝试使用它。
require_once APPPATH . 'controllers/PlentymarketsRestClien.php';
class Dashboard extends PlentymarketsRestClien {
....
}
推荐阅读
- sed - 命令行参数与 .sed 文件输入的差异
- javascript - 使用 JavaScript 在 SortableJS 可排序列表上模拟拖放
- c++ - Qt,将参数传递给函数
- ios - 如何在 GFlops 中估计 OpenGL ES 着色器/金属性能
- node.js - 如何识别来自用户的输入与哪张自适应卡相关?
- javascript - 选择选项继续显示相同的值
- c# - 配置多个一对一关系的正确方法是什么?
- java - 如何验证我的代码是否可以访问表
- python - 不知道如何强制 int64 和 float64
- highcharts - Highcharts,如何在不设置颜色的情况下使用渐变?