本文介绍了将Mailjet API v3包装程序集成为Codeigniter库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将集成到我的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存储库的一步指导


  1. APPPATH.'config / config中设置 $ config ['composer_autoload'] = TRUE; php'

  2. APPPATH composer.json c> location

  3. 通过控制台执行 composer install 命令,这将使供应商和其他相关文件和文件夹

  4. 在控制器或其他代码中使用它,如下面的示例所示

  1. Set $config['composer_autoload'] = TRUE; in APPPATH.'config/config.php' file
  2. Put composer.json file with wanted repositories/projects in APPPATH location
  3. Do the job with composer install command through console which will make vendor and other related files and folders inside
  4. 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库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:50