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.

Bootstrap registerModules error

Hi,

I have an error in the bootstrap file when I load the my modules :

Service 'Apps\Frontend\Module' wasn't found in the dependency injection container

I'm using the multi modules architecture like this :

multiple/
├── common
│   ├── config
│   │   ├── config.php
│   │   ├── modules.php
│   │   └── services.php
│   ├── library
│   │   └── Elements.php
│   │   └── Tools.php
│   │   └── PhpMailer.php
│   ├── models
│   │   └── User.php
├── apps
│   ├── frontend
│   │   ├── Module.php
│   │   ├── controllers
│   │   │   ├── ControllerBase.php
│   │   │   └── IndexController.php
│   │   ├── plugins
│   │   │   └── SecurityPlugin.php
│   │   │   └── NotFoundPlugin.php
│   │   ├── cache
│   │   │   └── cache1.php
│   │   │   └── cache2.php
│   │   └── views
│   │       ├── index
│   │       │   └── index.phtml
│   │       └── index.phtml
│   │
│   └── api
│       ├── controllers
│       │   └── RestController.php
│       └── Module.php
│       
├── .htaccess
├── index.html
└── public
    └── index.php
    └── .htaccess

And here is the way how I load my modules in the bootstrap file :

    /**
     * Read the configuration
     */
    $config = include __DIR__ . "/../common/config/config.php";

    /**
     * Read auto-loader
     */
    include __DIR__ . "/../common/config/loader.php";

    /**
     * Read services
     */
    include __DIR__ . "/../common/config/services.php";

    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application($di);

    $application->registerModules(
        array(
            'frontend' => array(
                'className' => 'Apps\Frontend\Module',
                'path'      => '../apps/frontend/Module.php',
            ),
            'api'  => array(
                'className' => 'Apps\Api\Module',
                'path'      => '../apps/api/Module.php',
            )
        )
    );

    echo $application->handle()->getContent();

    \Phalcon\Mvc\Model::setup([ 'notNullValidations' => false ]);

Could you help me ?

Thanks.



114.4k
Accepted
answer
edited Apr '16

But why you have:

Service 'Apps\Frontend\Module' wasn't found in the dependency injection container ?

try to find ->get('Apps\Frontend\Module') or ->getShared('Apps\Frontend\Module') is it reutrned anywhere in your code ? Are you sure that ../apps/frontend/Module.php have proper namespace ?



15.1k
edited Apr '16

You found the issue. I have set a bad namespace... In the Module.php I had set :

namespace Apps\Frontend\Module;

instead of

namespace Apps\Frontend;

Thank you.