Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



2.9k

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



2.9k

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



1.5k
Accepted
answer

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

\Phalcon\Di::getDefault()



2.9k

Thanks for your answer, it does work!

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

\Phalcon\Di::getDefault()