Ich klinke mich hier mal ein, da ich das gleiche Problem habe, nur in einem Bundle. Contao scheint meinen Controller nicht zu finden, oder zu ignorieren.
Im Unterschied zum Vorherigen kommt bei mir aber (leider) noch PHP 7.4 zum Einsatz.
Mein Code:
src/ContaoManager/Plugin.php
PHP-Code:
<?php
namespace MyVendor\Jobfeed\ContaoManager;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use MyVendor\Jobfeed\JobfeedBundle;
class Plugin implements BundlePluginInterface {
public function getBundles(ParserInterface $parser): array
{
return [
BundleConfig::create(JobfeedBundle::class)
->setLoadAfter([ContaoCoreBundle::class]),
];
}
public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
{
$file = __DIR__.'/../Resources/config/routes.yml';
return $resolver->resolve($file)->load($file);
}
}
src/Controller/JobfeedController.php
PHP-Code:
<?php
namespace MyVendor\Jobfeed\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/example")
*/
class JobfeedController {
public function __invoke(Request $request): Response {
return new Response('Hello World');
}
}
src/DependencyInjection/JobfeedExtension.php
PHP-Code:
<?php
namespace MyVendor\Jobfeed\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class JobfeedExtension extends Extension {
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
src/Resources/config/routes.yml
Code:
myvendor.jobfeed.controller:
resource: ../../Controller
type: annotation
src/Resources/config/services.yml
Code:
services:
_defaults:
autoconfigure: true
src/JobfeedBundle.php
PHP-Code:
<?php
namespace MyVendor\Jobfeed;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class JobfeedBundle extends Bundle{}
composer.json
Code:
{
"name": "myvendor/jobfeed",
"description": "XML Jobfeed 3",
"type": "contao-bundle",
"require": {
"contao/core-bundle": "^4.13"
},
"autoload": {
"psr-4": {
"MyVendor\\Jobfeed\\": "src/"
}
},
"conflict": {
"contao/manager-plugin": "<2.0 || >=3.0"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
},
"extra": {
"contao-manager-plugin": "MyVendor\\Jobfeed\\ContaoManager\\Plugin"
}
}
Output von
Code:
vendor/bin/contao-console debug:router 'MyVendor\Jobfeed\Controller\JobfeedController
Code:
17:18:11 CRITICAL [console] Error thrown while running command "debug:router 'MyVendor\Jobfeed\Controller\JobfeedController'". Message: "The route "MyVendor\Jobfeed\Controller\JobfeedController" does not exist." ["exception" => Sym
fony\Component\Console\Exception\InvalidArgumentException^ { …},"command" => "debug:router 'MyVendor\Jobfeed\Controller\JobfeedController'","message" => "The route "MyVendor\Jobfeed\Controller\JobfeedController" does not exist."]
The route "MyVendor\Jobfeed\Controller\JobfeedController" does not exist.
debug:router [--show-controllers] [--format FORMAT] [--raw] [--] [<name>]
Und bei Aufruf von /example bekomme ich die 404 Seite.. Was mache ich falsch?
Ich bin über jeden Hinweis dankbar!
VG
Kyuhunter