问题描述
如何将集成到我的Codeigniter中安装为库?
How can I integrate the Mailjet API PHP wrapper into my Codeigniter installation as a library?
这是简单的将中所述的作曲家。
Yes, you are on right track. But you don't need to create CI library. Use Mailjet
repository library in controller as well. Just use composer as stated in CI docs.
在CodeIgniter中使用github存储库的一步指导
- 在
APPPATH.'config / config中设置
$ config ['composer_autoload'] = TRUE;
php' - 在
APPPATH $ c $中放置所需存储库/项目的
composer.json
c> location - 通过控制台执行
composer install
命令,这将使供应商
和其他相关文件和文件夹 - 在控制器或其他代码中使用它,如下面的示例所示
- Set
$config['composer_autoload'] = TRUE;
inAPPPATH.'config/config.php'
file - Put
composer.json
file with wanted repositories/projects inAPPPATH
location - Do the job with
composer install
command through console which will makevendor
and other related files and folders inside - Use it when needed in controller or in other code as shown in example bellow
示例控制器Mailman.php
example controller Mailman.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
use \Mailjet\Resources;
class Mailman extends CI_Controller
{
private $apikey = 'apy__key__here';
private $secretkey = 'apy__secret__here';
protected $mj = NULL;
public function __construct()
{
// $this->mj variable is becoming available to controller's methods
$this->mj = new \Mailjet\Client($this->apikey, $this->apisecret);
}
public function index()
{
$response = $this->mj->get(Resources::$Contact);
/*
* Read the response
*/
if ($response->success())
var_dump($response->getData());
else
var_dump($response->getStatus());
}
}
如果您明确要使用Mailjet )存储库,请检入如何创建自定义库并将其合并代码上面用它。 Personaly我这样使用存储库,以避免不必要的加载和解析足够的库。
If you explicitly want to use Mailjet (or any other) repository through CI library, check in docs how to create custom library and merge this code above with it. Personaly I use repositories this way to avoid unnecessarily loading and parsing sufficient libraries.
这篇关于将Mailjet API v3包装程序集成为Codeigniter库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!