Way to require an autoload in one file on a Prestashop module?

前端 未结 2 1584
-上瘾入骨i
-上瘾入骨i 2021-01-16 03:53

I\'m trying to use a set of libraries with Composer for a Prestashop module.

My current approach is to include the vendor/autoload.php file on every fil

2条回答
  •  半阙折子戏
    2021-01-16 04:26

    I've found the way to do it!

    The actionDispatcher hook was working for me with models, hooks, but not with controllers.

    Seems like there is a not documented hook called moduleRoutes which loads before any controller.

    So I've been able to autoload in all my module's classes this way:

    registerHook('moduleRoutes'); // Register the hook
      }
    
    
      public function hookModuleRoutes() {
        require_once __DIR__.'/vendor/autoload.php'; // And the autoload here to make our Composer classes available everywhere!
      }
    

提交回复
热议问题