Installation:
composer require aleste/crud-generator
Register the bundle in config/bundles.php:
return [
// ...
Aleste\CrudGeneratorBundle\AlesteCrudGeneratorBundle::class => ['all' => true],
];
Generate a CRUD:
Use the console command to scaffold a CRUD for an existing entity (e.g., Post):
php bin/console generate:crud AlesteCrudGeneratorBundle:Crud Post
This creates:
src/Controller/PostCrudController.php)templates/crud/post/)config/routes/crud.yaml)First Use Case:
Access the generated CRUD at /post/crud. The bundle provides:
Entity-Centric Generation:
CrudGeneratorBundle's configuration in config/packages/aleste_crud_generator.yaml:
aleste_crud_generator:
cruds:
Post:
fields:
- { property: 'title', type: 'text' }
- { property: 'content', type: 'textarea' }
filters:
- { property: 'published', type: 'boolean' }
Template Overrides:
vendor/aleste/crud-generator-bundle/Resources/views/crud/ to templates/crud/.templates/crud/post/index.html.twig.Dynamic Routing:
config/routes/crud.yaml. Extend them by adding custom routes:
post_crud_custom:
path: /post/custom
controller: App\Controller\PostCrudController::customAction
Form Customization:
// src/Form/PostType.php
class PostType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('customField', TextType::class);
}
}
$this->formFactory->createNamedBuilder('post', PostType::class, $post);
Event Listeners:
CrudGenerateEvent) to modify generation behavior:
// src/EventListener/CrudGenerateListener.php
class CrudGenerateListener implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
CrudEvents::PRE_GENERATE => 'onPreGenerate',
];
}
public function onPreGenerate(CrudGenerateEvent $event) {
$event->setTemplatePath('custom/path');
}
}
API Integration:
# config/routes/api.yaml
app_post_crud_api:
path: /api/posts
controller: App\Controller\PostCrudController::apiListAction
methods: [GET]
Bundle Compatibility:
sensio/generator-bundle are outdated. Manually generate controllers if issues arise.Template Caching:
php bin/console cache:clear
Filter Bundle Conflicts:
config/packages/lexik_form_filter.yaml:
lexik_form_filter:
filter_form_types:
- App\Form\Type\PostFilterType
ignored_form_types:
- Symfony\Component\Form\Extension\Core\Type\FormType
Entity Changes:
php bin/console generate:crud AlesteCrudGeneratorBundle:Crud Post --force
Pagination Issues:
knp_paginator is configured in config/packages/knp_paginator.yaml:
knp_paginator:
page_range: 5
default_options:
page_name: page
sort_field_name: sort
sort_direction_name: direction
distinct: true
Export Problems:
phpoffice/phpexcel may be missing. Install manually:
composer require phpoffice/phpexcel
Check Generated Files:
var/cache/dev/ for compiled templates and routes.src/Controller/ for generated controllers.Enable Debug Mode:
# config/packages/dev/debug.yaml
framework:
profiler: { only_exceptions: false }
Log Events:
config/packages/monolog.yaml:
monolog:
handlers:
crud:
type: stream
path: "%kernel.logs_dir%/crud.log"
level: debug
Custom Actions:
public function bulkAction(Request $request) {
$ids = $request->request->get('ids');
// Custom logic (e.g., bulk delete)
return $this->redirectToRoute('post_crud_index');
}
{{ form_start(form.bulk_action) }}
<button type="submit">Bulk Action</button>
{{ form_end(form.bulk_action) }}
Dynamic Field Mapping:
aleste_crud_generator.yaml:
fields:
- { property: 'createdAt', type: 'datetime', options: { callback: 'App\Callback\FormatDate' } }
Security:
public function indexAction() {
$this->denyAccessUnlessGranted('ROLE_POST_MANAGER');
// ...
}
Internationalization:
translations/messages.en.yaml:
'post.crud.title': 'Post Title'
'post.crud.actions.edit': 'Edit Post'
Testing:
public function testCrudGeneration() {
$client = static::createClient();
$crawler = $client->request('GET', '/post/crud');
$this->assertSelectorTextContains('h1', 'Posts');
}
How can I help you explore Laravel packages today?