I don't know if it's a mistake or not.
I have a problem.
I'm converting an old module to a new J5 format.
There is a problem after creating the dispatcher file along the way
/modules/mod_multi_form/src/Dispatcher/Dispatcher.php .
The site gives this error.
That is, as if the file manager include 2 times. But I don't include this file anywhere, this process is done by the built-in Joomla mechanism.
Of course, I have already deleted the module and reinstalled it, and of course I have already cleaned the cache (folder)."autoload_psr4.php ".
In the XML file of the module, he also specified
<namespace path="src">Exoffice\Module\MultiForm</namespace>
It wouldn't be bad if the container error showed more information, such as which class the container can't find.
Tell me what to do. I've been trying to find the Dispatcher error for 2 full days now, The names of the namespace and the class match, but nevertheless it's as if the container can't find the dispatcher.
The file defines the full class name for the module manager, I display it on the screen, the name completely matches the class of the module manager. But I can't find the error.
/libraries/src/Dispatcher/ModuleDispatcherFactory.php
$className = '\\' . trim($this->namespace, '\\') . '\\' . $name . '\\Dispatcher\\Dispatcher';
echo '<pre>$className</pre>;class Exoffice\Module\MultiForm\Site\Dispatcher\Dispatcher in folder /src/Dispatcher
Stack trace:
#0 /libraries/vendor/composer/ClassLoader.php(427): {closure:Composer\Autoload\ClassLoader::initializeIncludeClosure():575}('/home/e/exoffic...')
#1 /libraries/src/Autoload/ClassLoader.php(59): Composer\Autoload\ClassLoader->loadClass('Exoffice\\Module...')
#2 [internal function]: Joomla\CMS\Autoload\ClassLoader->loadClass('Exoffice\\Module...')
#3 /libraries/src/Dispatcher/ModuleDispatcherFactory.php(68): class_exists('\\Exoffice\\Modul...')
#4 /libraries/src/Extension/Module.php(75): Joomla\CMS\Dispatcher\ModuleDispatcherFactory->createDispatcher(Object(stdClass), Object(Joomla\CMS\Application\SiteApplication), NULL)
#5 /libraries/src/Helper/ModuleHelper.php(284): Joomla\CMS\Extension\Module->getDispatcher(Object(stdClass), Object(Joomla\CMS\Application\SiteApplication))
#6 /libraries/src/Helper/ModuleHelper.php(160): Joomla\CMS\Helper\ModuleHelper::renderRawModule(Object(stdClass), Object(Joomla\Registry\Registry), Array)
#7 /libraries/src/Document/Renderer/Html/ModuleRenderer.php(99): Joomla\CMS\Helper\ModuleHelper::renderModule(Object(stdClass), Array)
#8 /libraries/src/Document/Renderer/Html/ModulesRenderer.php(51): Joomla\CMS\Document\Renderer\Html\ModuleRenderer->render(Object(stdClass), Array, NULL)
#9 /libraries/src/Document/HtmlDocument.php(578): Joomla\CMS\Document\Renderer\Html\ModulesRenderer->render('main-bottom', Array, NULL)
#10 /libraries/src/Document/HtmlDocument.php(897): Joomla\CMS\Document\HtmlDocument->getBuffer('modules', 'main-bottom', Array)
#11 /libraries/src/Document/HtmlDocument.php(650): Joomla\CMS\Document\HtmlDocument->_renderTemplate()
#12 /libraries/src/Application/CMSApplication.php(1120): Joomla\CMS\Document\HtmlDocument->render(false, Array)
#13 /libraries/src/Application/SiteApplication.php(745): Joomla\CMS\Application\CMSApplication->render()
#14 /libraries/src/Application/CMSApplication.php(309): Joomla\CMS\Application\SiteApplication->render()
#15 /includes/app.php(58): Joomla\CMS\Application\CMSApplication->execute()
#16 /index.php(51): require_once('/home/e/exoffic...')
#17 {main}I'm redoing this module in a new format, there may be other errors. But in this case, I'm wondering why the dispatcher file gets turned on several times, and each time the content provider can't find the right class with the right namespace in the dispatcher file.
but the namespace and the class name are exactly correct.
| Labels |
Added:
No Code Attached Yet
|
||
@beni71
Wow cool.
Thank you very much.
Indeed, the problem was the USE namespaces
use Joomla\CMS\Dispatcher\Dispatcher;Note: The rest of the files are Dispatcher_.php and copies Dispatcher.php not used. Since there is only one default folder for the namespace, I started copying these files in different path locations after an main error was detected.
So thanks a lot for the help.
But then it becomes obvious, the following questions:
| Status | New | ⇒ | Closed |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2025-11-29 04:35:08 |
| Closed_By | ⇒ | korenevskiy |
@korenevskiy You are welcome. Here are my answers:
I first tried to debug the code with the IDE (see below) but I could not find the issue, but then I opened the Dispatcher.php and then it showed those red lines.
I use the IDE Visual Studio Code (on a Windows 11 system, where Bearsampp is installed). In Visual Studio Code, I use the standard extensions for PHP development like:
-PHP intelephense
-PHP Debug
-phpcs
-PHP Phan (Analyzer)
-phpstan
I think I did follow https://developer.joomla.org/coding-standards/html.html
and https://docs.joomla.org/Joomla_CodeSniffer
to see formatting issues which are against the Joomla coding standards.
Wenever a php file is opened in the IDE, the code is getting analyzed and there is a then a visual feedback of errors, deprecations and formatting issues.
With this IDE it is also possible to debug the php code (with breakpoints, step into/over,..). I use XDebug for that.
In Visual Studio Code, navigate to View > Problems. There is also a indication in bottom bar, left hand side.
From the debugging session I can see that include $file; throws a fatal exception and this exception is then catched in Joomla and Joomla graps as mutch information as possible already. I don't think the Joomla code could be improved.
in the file /modules/myModule/services/provider.php we register a ModuleDispatcherFactory, which means that if there is a ModuleDispatcherFactory and there is no dispatcher class, we can think that there is an ERROR.
@korenevskiy In the attached zip file, there is:
Both files contains a class with the same name and namespace. Are both needed? What happens when you remove the file Dispatcher_.php?
In my VS code it shows errors of the src/Dispatcher/Dispatcher.php:
When I delete line 13:
use Joomla\CMS\Dispatcher\Dispatcher;
Then the error is gone and at least the dispatcher error "Cannot redeclare..." is gone as well.
Might it solve the reported issue?
(My code base is Jommla 6.0.1)