Integrating Mailjet API V3 Wrapper as Codeigniter Library

Integrating Mailjet API v3 wrapper as Codeigniter 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.

If you want CodeIgniter to use a Composer auto-loader, just set $config['composer_autoload'] to TRUE or a custom path in application/config/config.php.

Step by step instruction for using github repository in CodeIgniter

  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

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());
}
}

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.

Integrating AWS PHP SDK with Codeigniter

I would recommend using composer to install AWS SDK for PHP. It will be a lot easier for you to pick up the latest version directly without code changes since the SDK keeps on releasing new features/services/bug fixed frequently.

Also you can access new services directly when they launch by depending on latest version of SDK.

I am trying to set up microsoft azure storage acces using code igniter. It is not working

As you are using composer, you can install CodeIgniter with one command. See CodeIgniter Composer Installer for details.

composer create-project kenjis/codeigniter-composer-installer codeigniter

Then cd into your ci project path and install Azure SDK for PHP by running the command:

composer require microsoft/windowsazure

After these done, you can use the following code to work with Azure storage in the controller.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use WindowsAzure\Common\ServicesBuilder;

class Welcome extends CI_Controller {

public function index()
{
$account = 'yourAccoutName';
$key = 'yourAccessKey';
$connectionString = "DefaultEndpointsProtocol=http;AccountName=$account;AccountKey=$key";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
// ...

$this->load->view('welcome_message');
}
}

Codeigniter 3: How to use composer packages? (Twilio SDK)

In Config.php, put these lines of code

$config['composer_autoload'] = TRUE;
require_once FCPATH . 'vendor/autoload.php';

and make changes in your controller like-

<?php

use Twilio\Rest\Client;

defined('BASEPATH') OR exit('No direct script access allowed');

class Test extends CI_Controller {

public function twilio()
{
$client = new Client($AccountSid, $AuthToken);

}
}

Refer:
http://theprofessionguru.com/android/how-to-load-composers-vendor-autoloadphp-in-codeigniter

I am trying to set up microsoft azure storage acces using code igniter. It is not working

As you are using composer, you can install CodeIgniter with one command. See CodeIgniter Composer Installer for details.

composer create-project kenjis/codeigniter-composer-installer codeigniter

Then cd into your ci project path and install Azure SDK for PHP by running the command:

composer require microsoft/windowsazure

After these done, you can use the following code to work with Azure storage in the controller.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use WindowsAzure\Common\ServicesBuilder;

class Welcome extends CI_Controller {

public function index()
{
$account = 'yourAccoutName';
$key = 'yourAccessKey';
$connectionString = "DefaultEndpointsProtocol=http;AccountName=$account;AccountKey=$key";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
// ...

$this->load->view('welcome_message');
}
}


Related Topics



Leave a reply



Submit