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