Structure:
Code:
contao4/
|- src/
|- ContaoManager/
|---- Plugin.php
|- Controller/
|---- DefaultController.php
|- Resources/
|---- config/
|- routing.yml
PHP-Code:
<?php
// src/ContaoManager/Plugin.php
use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\HttpKernel\KernelInterface;
class Plugin implements RoutingPluginInterface
{
/**
* {@inheritdoc}
*/
public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
{
return $resolver
->resolve(__DIR__.'/../src/Resources/config/routing.yml')
->load(__DIR__.'/../src/Resources/config/routing.yml')
;
}
}
PHP-Code:
<?php
// src/Controller/DefaultController.php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
class DefaultController
{
/**
* @Route("/ajax")
*
* @return JsonResponse
*/
public function ajaxAction()
{
return new JsonResponse(['Hello World!']);
}
}
Code:
# src/Resources/config/routing.yml
app:
resource: "@AppBundle/Controller"
type: annotation
composer.json:
Code:
{
…,
"autoload": {
"psr-4": { "App\\": "src/" },
}
}
Code:
vendor/bin/contao-console cache:clear --no-warmup
vendor/bin/contao-console cache:warmup
composer dump-autoload