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

余生长醉 提交于 2019-12-01 13:22:13

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:

<?php

if (!defined('_PS_VERSION_'))
    exit;

//_PS_MODULE_DIR_

require_once __DIR__.'/vendor/autoload.php'; // Autoload here for the module definition

class MyCustomModule extends Devnix\Prestablocks\Module { // My custom Prestashop framework (in experimental phase, https://github.com/devnix/prestablocks)

  // ...

  public function install() {
    return
      parent::install() &&
      $this->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!
  }

Maybe to re-route all scripts to one using htaccess/rewrite, then in that one before including prestashop files use autoload.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!