Creating a new Crud Controller

This guide will show you how to create a new Crud Controller for your project.

1. Create a new Crud Controller

Create a new Crud Controller by extending the Shopsys\AdministrationBundle\Controller\AbstractCrudController class and on your class, define attribute #[CrudController] with the entity class name.


<?php

declare(strict_types=1);

namespace App\Controller\Admin;

use App\Model\Order\Order;
use Shopsys\AdministrationBundle\Component\Attributes\CrudController;
use Shopsys\AdministrationBundle\Controller\AbstractCrudController;

#[CrudController(Order::class)]
class OrderController extends AbstractCrudController
{
    // That's it! The list page is now available
}

That's it! Now you have a new Crud Controller that is automatically registered as a service and will be available in the administration. By default, only the List action is enabled.

2. Configure Crud Controller (Optional)

You can implement the configure() method to customize the controller behavior:

use Shopsys\AdministrationBundle\Component\Config\ActionType;
use Shopsys\AdministrationBundle\Component\Config\CrudConfig;

public function configure(CrudConfig $config): void
{
    $config
        ->setTitle(ActionType::LIST, t('Orders management')) // Set the custom title of the list page
        ->setMenuSection('customers') // Set the menu section where the controller will be placed
    ;
}

Info

Default page titles and menu labels are generated automatically from the entity class name.

More configuration options can be found in the Crud Config reference.

Next Steps