We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

Getting module name in controller

Is there a smarter way than exploding the namespace to retrieve the currently active module in an environment which uses :module/:controller:?



98.8k
Accepted
answer

You can access the router to get the module that was routed:

$module = $this->router->getModuleName();

Hi, Please help me: How to getting module name in a class custom helper. I tried the code below but failed:

$router = $this->getDI()->get('router'); echo $router->getModuleName()