3

I am trying to create a simple component. After installation of the component I get the following error message in the admin view:

An error has occurred.
0 Invalid controller class: display

I've already seen this question from another user but adding the <namespace>-tag didn't solve the error.

mycomponent.xml
<?xml version="1.0" encoding="utf-8"?>
<extension version="1.0.0" type="component">
    <name>MyComponent</name>
    <namespace path="src">Firecase\Component\MyComponent</namespace>
    <administration>
        <menu>MyComponent</menu>
        <files folder="admin">
            <folder>services</folder>
            <folder>src</folder>
            <folder>tmpl</folder>
        </files>
    </administration>
</extension>
DisplayController.php
<?php
namespace Firecase\Component\MyComponent\Administrator\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\MVC\Controller\BaseController;

class DisplayController extends BaseController
{
    protected $default_view = 'mycomponent';

    public function display($cachable = true, $urlparams = array())
    {
        return parent::display($cachable, $urlparams);
    }
}
?>

provider.php
<?php
defined('_JEXEC') or die;

use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

return new class implements ServiceProviderInterface
{
    public function register(Container $container): void {
        $container->registerServiceProvider(new MVCFactory('\\Firecase\\Component\\MyComponent'));
        $container->registerServiceProvider(new ComponentDispatcherFactory('\\Firecase\\Component\\MyComponent'));
        $container->set(
            ComponentInterface::class,
            function (Container $container) {
                $component = new MVCComponent($container->get(ComponentDispatcherFactoryInterface::class));
                $component->setMVCFactory($container->get(MVCFactoryInterface::class));

                return $component;
            }
        );
    }
}
?>

directory structure
com_mycomponent
├─ admin
│  ├─ services
│  │  └─ provider.php
│  ├─ src
│  │  ├─ controller
│  │  │  └─ DisplayController.php
│  │  ├─ model
│  │  └─ view
│  │     └─ mycomponent
│  │        └─ HtmlView.php
│  └─ tmpl
│     └─ mycomponent
│        └─ default.php
├─ site
│  └─ src
│     ├─ controller
│     ├─ model
│     └─ view
└─ mycomponent.xml
17
  • File name DisplayController.php maybe?
    – Peli
    Commented Mar 7, 2023 at 17:38
  • most probably a typo in the provider.php file, that can cause this invalid diplay controller error. Please check that file or copy the content of provider.php file here in your question
    – Zollie
    Commented Mar 7, 2023 at 17:48
  • @Peli - I mean, you are right basically, according to the PSR standards, filename must match the casing of the terminating class name, but as I tested that in Joomla4, if you name the controller file with lower cases, that does not raise or cause this error for some reasons. However, if you reference that for example in provider.php with wrong casing, that causes this error.
    – Zollie
    Commented Mar 8, 2023 at 7:58
  • 1
    @Zollie, sadly I didn't find a solution yet. Joomla and PHP version all all up to date. I will continue developing and testing my component locally (where the error doesn't occur), but sooner or later it has to work. So I will keep looking for solutions.
    – firecase
    Commented Mar 15, 2023 at 10:16
  • 2
    @firecase, could you provide a screen shot of your directory structure of the component for us to look at? In each case where I have seen the same message when moving to a live *nix server from a local dev environment on windows the issues has always been a problem with the case of a directory, a file name or namespace entry so I am thinking we need to see more of your structure to assist you further
    – Irata
    Commented Mar 16, 2023 at 7:59

2 Answers 2

1

You have a lowercase 'f' in firecase, it should be Firecase. Namespaces in Joomla are very particular about having the first character of each level as an uppercase.

And you have a path of "src/", it is most likely you only need to use "src".

4
  • Good point - Class names MUST be declared in StudlyCaps. and follow psr-4 standards php-fig.org/psr/psr-4
    – Zollie
    Commented Mar 8, 2023 at 4:37
  • I've tried changing the namespace and src/ to src. Unfortunately it didn't fix the error.
    – firecase
    Commented Mar 8, 2023 at 8:52
  • I just checked one of my provider.php files and I don't have the ": void" in mine, could this be the problem? public function register(Container $container) { Commented Mar 16, 2023 at 6:34
  • @GlennArkell, I checked a couple of my provider.php files and they don't have the :void statement either.
    – Irata
    Commented Mar 16, 2023 at 7:54
0

Try changing the following

<namespace path="src">Firecase\Component\MyComponent</namespace>

to

<namespace path="src/">Firecase\Component\MyComponent</namespace>

Adding the slash may fix the path attribute to the correct path.

Also check

<extension version="1.0.0" type="component">

Have you tried changing it to

<extension type="component" method="upgrade">

ADDED:

I ran into same problem. In my case some of Joomla's core methods were overridden. Try updating your Joomla in the Dashboard and then "Upload and Update".

6
  • src with or without the slash does not seem to matter, I have installed components both ways without problems.
    – Zollie
    Commented Mar 8, 2023 at 11:14
  • I see. And the xml tag? I know I had problems with <extension version="1.0.0" type="component"> at a time. But still. Invalid display controller usually is some silly Namespace error from my own experience.
    – DeesreX
    Commented Mar 10, 2023 at 10:24
  • The xml tag is not really connected to the problem in the question. Yes, most probably Namespace problems in the files.
    – Zollie
    Commented Mar 10, 2023 at 10:42
  • Ironically I installed a component update, and now I have the same error too xD.
    – DeesreX
    Commented Mar 13, 2023 at 12:47
  • 1
    @Zollie. Turns out I override some joomla core methods.. ^^. so I fixed it using the Joomla updater to re-update the core files.
    – DeesreX
    Commented Mar 13, 2023 at 14:11

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.