We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How i can add external library to phalcon project?

I want to add PHPMailer to my phalcon-project. I put PHPMailer-dir to library-dir. How a can create object PHPMailer without "require" with full path to file?



98.9k

If PHPMailer is PSR-0 compliant you can use a namespaces/directories strategy, or map the class name directly to its path:

<?php

$loader = new \Phalcon\Loader();

$loader->registerClasses(
    array(
        "PHPMailer"         => "library/PHPMailer/PHPMailer.php",
    )
);

// register autoloader
$loader->register();

https://docs.phalcon.io/en/latest/reference/loader.html#registering-classes

... and if not, you still add it as suggested and map all underlying classes as well :-) Easy as a pie.

And you leave a note to the author of the library to (finally) make his library PSR-0 compliant.