普通网友 2017-03-01 13:19
浏览 67

如何在drupal 7中包含自动加载模块

I want to use aws-sdk for php client in a custom module of drupal. I need to include vendor/autoload.php in module. But when I include it, it gives me error. I have tried to include many ways but did not get success. I added it as:

require __DIR__.'/vendor/autoload.php'; at the top of the file of .module file. Then the website gets crashed. Please could you tell how I should use require __DIR__.'/vendor/autoload.php';

  • 写回答

1条回答 默认 最新

  • duanfu3390 2017-03-01 14:00
    关注

    I'm not sure about how drupal handles autoloading of external php modules. But with the experience of working with frameworks like laravel, cakephp and with composer, I'm sure that the target file which is index.php which routes to a number of different controllers in root directory already includes vendor/autoload.php. If it does not include, add the require statement which points to autoload.php relative to index.php or absolute path. Then using namespaces in php, you can use external php modules which are then autoloaded.

    require __DIR__.'/vendor/autoload.php'; // Incase vendor directory is in same level as index.php file
    require dirname(__DIR__).'/vendor/autoload.php'; // Incase vendor directory is in parent level as index.php file
    
    评论

报告相同问题?