Installation (Legacy Context) Since this bundle is archived and incompatible with Symfony 4+, use it only for legacy Symfony 2/3 projects. Install via Composer:
composer require sensio/generator-bundle
Enable the Bundle
Add to AppKernel.php (Symfony 2) or bundles.php (Symfony 3):
new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(),
First Use Case: Generate a CRUD Controller Run the interactive command:
php app/console generate:doctrine:crud
Follow prompts to specify:
AcmeBlogBundle:Post)yml, xml, php)src/Acme/BlogBundle/Controller/)Key Documentation
generate: namespace commands (e.g., generate:doctrine:form, generate:bundle).Doctrine-Driven Generation
generate:doctrine:crud to scaffold controllers, forms, and templates from an existing Doctrine entity.
php app/console generate:doctrine:crud AcmeBlogBundle:Post
generate:doctrine:form for specific fields.
php app/console generate:doctrine:form AcmeBlogBundle:Post title content
Bundle Scaffolding
php app/console generate:bundle --namespace=Acme/BlogBundle --format=yml --dir=src --bundle-name=BlogBundle
--format (yml/xml/php) and --dir (output path).Interactive Prompts
--no-interaction for scripting:
php app/console generate:doctrine:crud AcmeBlogBundle:Post --no-interaction
Template Customization
vendor/sensio/generator-bundle/Resources/SensioGeneratorBundle to app/Resources/SensioGeneratorBundle.Sensio\Bundle\GeneratorBundle\Generator\Doctrine\CrudGenerator). Place custom logic in app/Resources/SensioGeneratorBundle/Generator/.--symfony-dir to specify the Symfony root (e.g., --symfony-dir=../symfony for monorepos).Symfony 4+ Incompatibility
Class 'Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle' not found in Symfony 4+.MakerBundle instead. This bundle is not maintained for modern Symfony.Entity Not Found
No such entity or mapping during CRUD generation.php app/console doctrine:schema:validate).Template Overrides Not Loading
app/Resources/SensioGeneratorBundle are ignored.Resources/SensioGeneratorBundle/Generator/Doctrine/templates/crud.twig).Namespace Conflicts
use Acme\BlogBundle; instead of use Acme\BlogBundle\Entity;).--namespace flag or override templates to hardcode paths.--dry-run to preview changes without writing files:
php app/console generate:doctrine:crud AcmeBlogBundle:Post --dry-run
-v for detailed logs:
php app/console generate:bundle -v
src/ or custom directories. Common artifacts:
PostController.php)PostType.php)Resources/views/Post/index.html.twig).Custom Generators
Extend Sensio\Bundle\GeneratorBundle\Generator\Generator to create reusable generators. Example:
// app/Resources/SensioGeneratorBundle/Generator/MyCustomGenerator.php
namespace AppBundle\Generator;
use Sensio\Bundle\GeneratorBundle\Generator\Generator;
class MyCustomGenerator extends Generator {
public function generate() { ... }
}
Register in services.yml:
services:
app.my_custom_generator:
class: AppBundle\Generator\MyCustomGenerator
tags:
- { name: sensio_generator.generator }
Command Overrides
Override existing commands by extending Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand and updating the service definition.
Configuration
Customize behavior via config.yml:
sensio_generator:
bundle_name_generator: '%app.bundle_name_generator.class%' # Custom bundle name logic
bundle_prefix_generator: '%app.bundle_prefix_generator.class%' # Custom prefix logic
How can I help you explore Laravel packages today?