3

I'm building a simple component in Joomla 4, and after reading through some tutorials I feel like I've got it right - but I'm getting this error that I can't explain in the admin view

An error has occurred.
0 Invalid controller class: display

With logging enabled, this is what I see in everything.php:

#Fields: datetime   priority clientip   category    message
2022-11-18T17:52:12+00:00   CRITICAL ::1    error   Uncaught Throwable of type InvalidArgumentException thrown with message "Invalid controller class: display". Stack trace: #0 [ROOT]\libraries\src\Dispatcher\ComponentDispatcher.php(142): Joomla\CMS\Dispatcher\ComponentDispatcher->getController('display', 'Administrator', Array)
#1 [ROOT]\libraries\src\Component\ComponentHelper.php(355): Joomla\CMS\Dispatcher\ComponentDispatcher->dispatch()
#2 [ROOT]\libraries\src\Application\AdministratorApplication.php(143): Joomla\CMS\Component\ComponentHelper::renderComponent('com_testcomponent')
#3 [ROOT]\libraries\src\Application\AdministratorApplication.php(186): Joomla\CMS\Application\AdministratorApplication->dispatch()
#4 [ROOT]\libraries\src\Application\CMSApplication.php(294): Joomla\CMS\Application\AdministratorApplication->doExecute()
#5 [ROOT]\administrator\includes\app.php(61): Joomla\CMS\Application\CMSApplication->execute()
#6 [ROOT]\administrator\index.php(32): require_once('F:\\xampp\\htdocs...')
#7 {main}

My DisplayController.php file is at:

joomla\administrator\components\com_testcomponent\src\Controller\DisplayController.php

<?php

namespace Joomla\Component\Testcomponent\Administrator\Controller;

use Joomla\CMS\MVC\Controller\BaseController;

\defined('_JEXEC') or die;

class DisplayController extends BaseController
{
    protected $default_view = 'orders';
}
2
  • The controller seems in order. Post the contents of the service provider file (services/provider.php). And the <namespace> tag of the XML manifest.
    – Sharky
    Commented Nov 19, 2022 at 8:09
  • @Sharky apologies for the late reply, I was traveling for the holiday. Seems like you were right on, the namespace was not included in my manifest.
    – James
    Commented Nov 29, 2022 at 16:41

3 Answers 3

2

I was having the same problem! I struggled a whole day with why this error comes up; even a namespace path like

<namespace path="src/">TestComp\Component\Testcomponent</namespace>

has been given in the manifest file.

After reverse engineering Joomla's 'hello world' example @ https://docs.joomla.org/J4.x:Developing_an_MVC_Component/Developing_a_Basic_Component#helloworld.xml, I found a very interesting part which seems to be responsible for this error in my case.

In the manifest file, there is the tag field <name></name>. Usually, I thought here we could free define a name for our component, because there is not much info in the documentation. In the past, very often the raw name of the component has been typed here, eg <name>com_helloworld</name>. In the documentation from Joomla, you see that normal names can also be given. In this example it is <name>Hello World</name>.

And here comes the important point, if the name does not match the component name then you will encounter the error: 'Invalid Controller class: display'. Debugging showed me, that the responsible controller file will not be loaded. In my example I developed a component with the name 'com_testdev'. In the field of the manifest I typed <name>Test Development</name>. With this name the mentioned error comes up. Changing the the field to <name>Test Dev</name> resolved the problem!

1

I added a namespace to my manifest file, and the issue is resolved.

<namespace path="src/">TestComp\Component\Testcomponent</namespace>
0

For me after upgrading to Joomla 4.3 I got this error on random Joomla pages. I found that I had many menu items that were for whatever reason pointing to the wrong component (in my case com_template mostly and one pointing to nothing with id 0). To see if you have any dangling component menu items query your db with the following:

SELECT * FROM `#__menu` WHERE 1 AND link LIKE '%=com_content%' AND type = 'component' AND component_id != (SELECT extension_id FROM #__extensions WHERE name = 'com_content');

Export the previous as a backup if needed to have a reference of which ones are off. To set them right and get rid of the error try executing in your db:

UPDATE `#__menu` SET `component_id` = (SELECT extension_id FROM #__extensions WHERE name = 'com_content' LIMIT 1) WHERE 1 AND link LIKE '%=com_content%' AND type = 'component' AND component_id != (SELECT extension_id FROM #__extensions WHERE name = 'com_content' LIMIT 1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.