Controllers & Routes
Basic Controller
<?php
namespace Plugins\MyPlugin\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route(name: 'plugin_my_plugin_')]
class MyController extends AbstractController
{
#[Route('/', name: 'index', methods: ['GET'])]
public function index(): Response
{
return $this->render('@PluginMyPlugin/index.html.twig', [
'message' => 'Hello from My Plugin!'
]);
}
#[Route('/dashboard', name: 'dashboard', methods: ['GET'])]
public function dashboard(): Response
{
// Your logic here
return $this->render('@PluginMyPlugin/dashboard.html.twig');
}
#[Route('/api/data', name: 'api_data', methods: ['GET'])]
public function apiData(): Response
{
$data = ['status' => 'ok', 'message' => 'API response'];
return $this->json($data);
}
}Routing Conventions
Dependency Injection in Controllers
Form Handling
Security and Permissions
Template Rendering
JSON Responses
Redirects
Flash Messages
Service Registration
Related Guides
Last updated