Mailjet API v3 Shell Integration as Codeigniter

How to integrate the Mailjet API PHP wrapper into my Codeigniter installation as a library?

It's as simple as putting the contents of the repository in application/libraries/Mailjet, and then creating a file Mailjet.phpin application/librariesthat Mailjet initializes, as shown below?

require 'Mailjet/vendor/autoload.php';

use \Mailjet\Resources;

$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));

Please let me know if I am on the right track. Thank.

0
source share
1 answer

, . CI. Mailjet . , CI docs.

, CodeIgniter Composer, $config ['composer_autoload'] TRUE application/config/config.php.

github CodeIgniter

  • $config['composer_autoload'] = TRUE; APPPATH.'config/config.php'
  • composer.json / APPPATH location
  • composer install , vendor
  • , ,

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 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 ( ) CI, docs, . Personaly , .

+3

Source: https://habr.com/ru/post/1658174/


All Articles