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.

'Module '------' isn't registered in the application container'

This is an exception when the module is not defined. Is there any event to catch that exception? Triying to use the beforeException over dispatcher does not works.

edited Sep '15

Modules are handled before the dispatch loop, so there is no way to catch it there. But since you're the one setting them up in the first place, I think it's one's job to handle unregistered module names... It makes sense; the whole dependency tree is set up depending on a module.

edited Sep '15

You could handle it like this:

/// index.php

try {
    // ...
    echo $application->handle()->getContent();
catch(Phalcon\Application\Exception $e) {
    if(preg_match('/^Module \'(.*?)\' isn\'t registered in the application container$/', $e->getMessage(), $match)) {
        // You can get the attempted module name from the router:
        echo '<pre>', var_dump($application->router->getModuleName()), '</pre>';
        // Or the regexp match
        echo '<pre>', var_dump($match[1]), '</pre>';
        // Then handle it as you wish...
        echo $application->handle('/error/e404')->getContent();
    // ...

It's not very nice... but works :P

edited Sep '15

Thanks @Lajos i didn't take the time to look at the application-front controller. Yep, I will have to catch it on the application.

Anyway, would be great to fire an event like the beforeException in dispatcher but from the application class. I will post it on gihub and if I fond time I will try to make a PR.

I wrote it quickly on 2.1.x branch. I didn't test it so if anyone is able to check it would be great. Thanks