Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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)



1.9k
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.