{"record":{"id":"bc91846d3fd799cc","repo":"phalcon/cphalcon","slug":"module-name-is-not-registered-in-the-applicati","errorCode":null,"errorMessage":"Module '{name}' is not registered in the application","messagePattern":"Module '(.+?)' is not registered in the application","errorType":"exception","errorClass":"Phalcon\\Application\\Exceptions\\ModuleNotRegistered","httpStatus":null,"severity":"error","filePath":"phalcon/Application/AbstractApplication.zep","lineNumber":69,"sourceCode":"     */\n    public function getDefaultModule() -> string\n    {\n        return this->defaultModule;\n    }\n\n    /**\n     * Gets the module definition registered in the application via module name\n     *\n     * @param string name\n     *\n     * @phpstan-return Closure|application_module_definition\n     */\n    public function getModule(string name) -> mixed\n    {\n        var module;\n\n        if unlikely !fetch module, this->modules[name] {\n            throw new ModuleNotRegistered(name);\n        }\n\n        return module;\n    }\n\n    /**\n     * Return the modules registered in the application\n     *\n     * @phpstan-return application_modules\n     */\n    public function getModules() -> array\n    {\n        return this->modules;\n    }\n\n    /**\n     * Register an array of modules present in the application\n     *","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Application/AbstractApplication.zep#L51-L87","documentation":"Phalcon\\Application\\AbstractApplication::getModule(name) looks up the module definition in the modules array populated by registerModules()/setModules(). If the key is absent it throws ModuleNotRegistered — the application has no definition (className/path/closure) for that module name.","triggerScenarios":"`$application->getModule('frontend')` before registerModules(), with a typo, or with wrong case (module keys are case-sensitive); a router/dispatcher forwarding to a module name that was never registered.","commonSituations":"Multi-module apps where the router returns a module name not present in the modules config; registering modules conditionally per environment and forgetting one; renaming a module directory without updating the modules array.","solutions":["Register the module: `$application->registerModules(['admin' => ['className' => Admin\\Module::class, 'path' => ...]])`","Verify the exact key: `var_dump(array_keys($application->getModules()))` and compare case","Ensure registration happens before anything (router, dispatcher forward, your own code) calls getModule()"],"exampleFix":"// before\n$module = $application->getModule('admin'); // ModuleNotRegistered\n// after\n$application->registerModules([\n    'admin' => ['className' => \\App\\Admin\\Module::class],\n]);\n$module = $application->getModule('admin');","handlingStrategy":"validation","validationCode":"$modules = $application->getModules();\nif (!isset($modules[$name])) {\n    throw new InvalidArgumentException('Unknown module: ' . $name . '. Registered: ' . implode(', ', array_keys($modules)));\n}\n$module = $application->getModule($name);","typeGuard":null,"tryCatchPattern":"try {\n    $module = $application->getModule($name);\n} catch (\\Phalcon\\Application\\Exceptions\\ModuleNotRegistered $e) {\n    $response->setStatusCode(404)->setContent('Module not found')->send();\n}","preventionTips":["Derive router module names and registerModules() keys from one shared config/constant list","Register all modules in a single bootstrap provider before routing runs","Add a startup assertion comparing router-returned module names against getModules() keys"],"tags":["application","modules","not-found","routing"],"backgroundTag":"module-not-registered","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}