Open
Description
Symfony allows controllers to return arrays and specify the #Template attribute to ease the use of templated responses without manual rendering. But the \EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface::index()
method is currently limited to the Response
object only:
interface DashboardControllerInterface
{
...
public function index(): Response;
}
The suggestion is to mix the return type with the array
type which will allow the dashboard index
method to return an array and specify a template with the attribute:
interface DashboardControllerInterface
{
...
public function index(): Response|array;
}
abstract class AbstractDashboardController extends AbstractController implements DashboardControllerInterface
{
...
public function index(): Response|array
{
...
}
}
Sample dashboard controller with custom index template:
class DashboardController extends AbstractDashboardController
{
#[Override]
#[Template('admin/dashboard.html.twig')]
public function index(): array
{
return [
'templateVar' => 'value',
];
}
Metadata
Assignees
Labels
No labels