Installation
composer require aleste/generator-bundle
Ensure SensioGeneratorBundle (~2.3) is installed (this bundle extends it).
Enable the Bundle
Add to config/bundles.php:
Aleste\GeneratorBundle\AlesteGeneratorBundle::class => ['all' => true],
First Use Case: Generate a CRUD with Pagination Run the generator command with pagination flags:
php bin/console generate:doctrine:crud --entity=App\Entity\Post --paginate --paginator=knp_paginator
--paginate enables pagination.--paginator=knp_paginator specifies the paginator bundle (default: knp_paginator or whiteoctober/paginator).Key Files to Review
src/Generator/Doctrine/Generator/EntityGenerator.php (core logic).src/Resources/config/services.xml (service overrides).src/Generator/Doctrine/Generator/FilterGenerator.php (filter templates).Generate a Filtered CRUD
php bin/console generate:doctrine:crud --entity=App\Entity\User --filter --filter-fields=name,email,role
--filter adds a filter form to the list action.--filter-fields specifies which fields to include in the filter.Customizing Filter Templates Override the default filter template by copying:
vendor/aleste/generator-bundle/src/Resources/views/Filter/filter.html.twig
to:
templates/AlesteGeneratorBundle/Filter/filter.html.twig
Integration with KNP Paginator
Ensure knp/paginator-bundle is installed and configured. The bundle auto-detects it for pagination.
Dynamic Field Selection
Use --fields to control which fields appear in the list/view/edit forms:
php bin/console generate:doctrine:crud --entity=App\Entity\Product --fields=id,name,price,stock
Bootstrap Integration The bundle includes Bootstrap 3/4/5 support by default. Customize via:
# config/packages/aleste_generator.yaml
aleste_generator:
bootstrap_version: 5 # Options: 3, 4, 5
Paginator Bundle Dependency
knp/paginator-bundle or whiteoctober/paginator-bundle is installed. If missing, pagination fails silently.--paginator=null to disable pagination.Filter Field Validation
--filter-fields=* to auto-detect all non-association fields.Template Overrides
AlesteGeneratorBundle/Filter/). A misplaced template will break rendering.php bin/console cache:clear) after template changes.Doctrine Lifecycle Conflicts
prePersist), the generator may not handle them correctly in the CRUD forms.Bootstrap Version Mismatch
bootstrap_version config matches your project’s assets.Enable Debug Mode
php bin/console debug:config aleste_generator
to verify configuration.
Check Generated Files
The bundle outputs files to src/Controller/, templates/, and config/routes/. Inspect these for errors.
Log Generator Output
Add --verbose to commands to see detailed generation steps:
php bin/console generate:doctrine:crud --entity=App\Entity\Post --verbose
Custom Generators
Extend Aleste\GeneratorBundle\Generator\Doctrine\Generator\EntityGenerator to add custom logic (e.g., API endpoints):
namespace App\Generator\Doctrine\Generator;
use Aleste\GeneratorBundle\Generator\Doctrine\Generator\EntityGenerator as BaseGenerator;
class CustomEntityGenerator extends BaseGenerator {
protected function configure() {
$this->addOption('api', null, 'Generate API endpoints');
}
}
Register the service in config/services.yaml:
services:
App\Generator\Doctrine\Generator\CustomEntityGenerator:
tags: ['generator']
Dynamic Field Mapping
Override getFields() in a custom generator to dynamically include/exclude fields based on logic (e.g., ACL rules).
Event Listeners Use Symfony events to modify generation behavior. Example:
// src/EventListener/GeneratorListener.php
use Aleste\GeneratorBundle\Event\GenerateEvent;
class GeneratorListener {
public function onGenerate(GenerateEvent $event) {
$event->setTemplate('custom_template.html.twig');
}
}
Bind the listener in config/services.yaml:
services:
App\EventListener\GeneratorListener:
tags:
- { name: kernel.event_listener, event: aleste.generator.generate, method: onGenerate }
How can I help you explore Laravel packages today?