We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how can I use the $config in the registerAutoloaders() when I work with the multi-module application?

I just work with the multi-module application I try to set the $di like

    <?php
        $di->set('config', $config);
    ?>

if I use a config file for every module to some path info,,, and how can I use the $config during the

    <?php
         public function registerAutoloaders()
        {

            $loader = new Loader();

            $loader->registerNamespaces(
                array(
                    'Multiple\Backend\Controllers' => '../apps/backend/controllers/',
                    'Multiple\Backend\Models'      => '../apps/backend/models/',
                )
            );

            $loader->register();
        }
    ?>

or, how can I reach the $di in the registerAutoloaders ?

thanks!

In basic Module implements class Module implements ModuleDefinitionInterface you can use something like class Module implements ModuleDefinitionInterface extends \Phalcon\DI\Injectable



5.0k

thanks for your answer, but I just work in Phalcon 1.3.4,,, and I can't find the param of di. Is there any other way to sovle it. thanks!

In 2.0 di passed as param https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/moduledefinitioninterface.zep



5.0k

In basic Module implements class Module implements ModuleDefinitionInterface you can use something like class Module implements ModuleDefinitionInterface extends \Phalcon\DI\Injectable

thanks for your answer, with your suggestion, I extend the \Phalcon\DI\Injectable like

    <?php
        class Module extends \Phalcon\DI\Injectable implements ModuleDefinitionInterface
        {
            ...
        }
    ?>

and I get another question, I want to use the $config in method registerAutoloaders(), so I need to use $this->getDI(), But, when I shall call the $this->setDI() the pass the $di to Module ?

thanks!

Just try. I think di will be setted by framework on creation



2.1k
Accepted
answer

devCat, to get to di if there is only one instance of DI.

\Phalcon\Di::getDefault()



5.0k

Thanks for your answer, it does work!

devCat, to get to di if there is only one instance of DI.

\Phalcon\Di::getDefault()