Reputation: 71
I got difficult to include composer autoload in Class file, it not working on require_once('../vendor/autoload.php');
require_once('phpmailer/PHPMailerAutoload.php');
require_once('../vendor/autoload.php');
class Test {
function X()
{ ... }
}
What is the proper way to load multiple include files in a class?
Upvotes: 5
Views: 12065
Reputation: 39380
If you (correctly) use composer you need do add only the vendor autoload file. Then add the other dependency via composer vendor library or add custom path (composer do the rest for you).
As example, more simply:
php composer.phar init
composer require phpmailer/phpmailer
Then your class should be like:
require_once('../vendor/autoload.php');
class Test {
function X()
{ ... }
}
Hope this help
Upvotes: 7
Reputation: 195
I think you want something like this
class Loader
{
public function __construct()
{
require_once('phpmailer/PHPMailerAutoload.php');
require_once('../vendor/autoload.php');
}
}
$loader = new Loader();
just add some function as you want
tell me if this help you ... goodluck
Upvotes: -3