The AropixelAdminBundle provides a custom command to quickly generate a CRUD (Create, Read, Update, Delete) interface based on an existing FormType.
In line with the bundle's philosophy, this command does not aim to provide a "one-size-fits-all" solution. Instead, it generates the boilerplate code (Controller and Templates) that you can then fully customize to fit your specific needs.
To generate a new CRUD, run the following command:
php bin/console aropixel:make:crud
The command will ask you for:
App\Entity\MyEntity).App\Form\MyEntityType).The command generates three main files:
Created in src/Controller/Admin/. It includes:
DataTableFactory to list your entities.FormType.Created in templates/admin/[entity]/index.html.twig. It extends [@AropixelAdmin](https://github.com/AropixelAdmin)/List/datatable.html.twig and is pre-configured to work with the Controller's DataTable.
Created in templates/admin/[entity]/form.html.twig. It extends [@AropixelAdmin](https://github.com/AropixelAdmin)/Form/base.html.twig and provides a consistent look and feel for both "new" and "edit" actions.
By default, only the ID column is generated in the index action. You should manually add the columns you want to display in your Controller:
// src/Controller/Admin/MyEntityController.php
public function index(DataTableFactory $dataTableFactory, DataTableRowFactoryInterface $rowFactory): Response
{
return $dataTableFactory
->create(MyEntity::class)
->setColumns([
['label' => 'ID', 'orderBy' => 'id'],
['label' => 'Title', 'orderBy' => 'title'],
['label' => 'Created At', 'orderBy' => 'createdAt'],
['label' => '', 'orderBy' => '', 'class' => 'no-sort'],
])
->render($rowFactory);
}
And update the template accordingly:
{# templates/admin/my_entity/index.html.twig #}
{% block datatable_body %}
<td>{{ item.id }}</td>
<td>{{ item.title }}</td>
<td>{{ item.createdAt|date('d/m/Y') }}</td>
<td class="text-right">
{{ list.actions(item, path('admin_myentity_edit', {id: item.id}), path('admin_myentity_delete', {id: item.id})) }}
</td>
{% endblock %}
The generated form template uses {{ form_rest(form) }}. You can customize the layout by overriding the formbody or mainPanel blocks as described in the Form Templates documentation.
How can I help you explore Laravel packages today?