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 connect composer-projects in phalcon autoload?

Hey everyone, it's me again :)

How i can connect anyone project with composer vendor/autoload?

For example: https://github.com/cmfcmf/OpenWeatherMap-PHP-Api

how injected it in phalcon? (namespaces, autoload, etc)



4.5k
Accepted
answer

You can use something like this

protected function autoLoader()
{
  $loader =new Loader();

  // Load composer vendor stuff
  $loader->registerFiles([ BASE_PATH . "/vendor/autoload.php" ]);

  // Register namespaces
  $loader->registerNamespaces([
    'Models'      => BASE_PATH . '/app/models',
    'Backend'     => BASE_PATH . '/backend',
    'Modules'     => BASE_PATH . '/backend/modules',
    'Plugins'     => BASE_PATH . '/app/plugins',
    'Controllers' => BASE_PATH . '/app/controllers',
  ]);

  // Register classes
  $loader->register();
}

I don't bother integrating it. In my bootstrap.php file, I just call the autoloader itself - that does the setup work.