cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Multi module / registerAutoloaders used config in bootstrap

Open Cmssspl opened this issue 13 years ago • 3 comments

W \ Phalcon \ Mvc \ ModuleDefinitionInterface -> registerAutoloaders should be shared di or registerAutoloaders method should not be required.

If you are in the config path we leave registerAutoloaders currently empty and registerNamespaces used in registerServices in order to be used in the config bootstrap (index.php)

public function registerAutoloaders($di) { ... }

Cmssspl avatar Jan 25 '13 07:01 Cmssspl

I am not sure that I understand this correctly.

You are saying that we should not use the registerAutoloaders in the interface?

What if you need to register an autoloader specific to that module?

You can always (when implementing your interface) leave that function empty and Phalcon will not execute it.

Can you please explain what you mean by the config path?

niden avatar Jan 25 '13 20:01 niden

  • Declare config ini file.
  • Loading it in the bootstrap ($ d-> set (config, ...))
  • I am part of the bootstrap.
  • Transfers to the module
  • Creating a namespace on the basis config ($ d-> get (config))

Manual says that in registerAutoloaders () (ModuleDefinitionInterface) add namespace and there I do not have access to the $ d to get config.

So you need to: registerAutoloaders () - leave blank and registerServices () can add, at this moment registerAutoloaders method () is not needed.

solution: registerAutoloaders () - not required registerAutoloaders () - has passed $ d -> registerAutoloaders (di)

Cmssspl avatar Jan 26 '13 19:01 Cmssspl

If you're using 0.8.0, the $di is passed to registerAutoloaders, however you can use an anonymous function if you don't want to implement the Module definition class:

<?php

// Register the installed modules
$application->registerModules(
    array(
        'frontend' => function($di) {
            //...
        },
        'backend' => function($di) {
            //...
        }
    )
);

ghost avatar Jan 26 '13 22:01 ghost