Reputation: 33
I’m looking at different mail services for using with my Codeigniter projects. Amongs them: Mandrill, Mailgun, Postmarkapp etc.
In most cases, there is already one or more Codeigniter libraries available but If I want to build on them, making simpler methods that are more suited to my projects and CMS workflow for instance, what’s the best way to approach without having to write the whole thing from scratch?
Is it best to create a new class that extends the existing CI library? and then include those two files? /libraries/mailgun & /libraries/my_mailgun.php
Upvotes: 3
Views: 2090
Reputation: 1069
You definatly answered your own question here.
Is it best to create a new class that extends the existing CI library? and then include those two files? /libraries/mailgun & /libraries/my_mailgun.php?
Yes, is the correct answer, this way you can Add new functionality to an existing library without having to reinvent 90% of the wheel.
class My_lib extends stock_lib
{
function newMethod1()
{
}
function newMethod2()
{
}
function etc()
{
}
}
As you already mentioned this will allow you to use your new functions as well as the existing functions to the parent class.
so, i should up-vote you for answering your own quesiton, and this answer is just a re-iteration of you answer.
Upvotes: 0
Reputation: 914
I'm using this method.
I put the put the external libary in /application/third_party, after I create a class in /application/libraries with name my_{project name}. Inside the my_{project name} I put a require_once as the follow code
require_once APPPATH."/third_party/projectname/main.php";
class Algumnome extends Project {
public function __construct($arg1 = 'defaultValueToProject', $arg2 = 'defaultValueToProject'){
parent::__construct($arg1, $arg2);
}
}
I my controller I call the lib like:
$this->load->library('algumnome');
$this->algumnome->method();
Upvotes: 1