We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Including Composer

What would be the best approach( or phalcon's best practice ) for including the composer autoloader within a project?

Currently i'm just doing a require, but i'm curious what the best practice is.

I'm far from an expert, but my guess would be to inject it into the di container:

In your bootstrap

    require '/path/to/Composer/loader';
    return $loaderObject;


in the file app/config/loader.php set :

include __DIR__ . "/../../vendor/autoload.php"

Dont set it in the di as @quasipickle suggested, it wont work as it should, you just need to include it.

Also if you want to use only composer (that's what i do), just comment the phalcon loader, and add your model, etc... directly into composer :

Example of composer.json :

    "require": {
        "php": ">=5.3.6",
        "phalcon/incubator": "dev-master",
    "autoload": {
        "classmap": ["models/"],
        "psr-0" : {
            "SomeLib"    :   "app/library"

Where classmap is equivalent to "registerdir" and "psr-0" is equivalent to "registerNamespace"

Thanks Sneaky. The first option is what I have been doing, but didn't know if there was a best practice. The second will be what I migrate to, it makes much more sense to keep everything in one place.

Thanks again.