cedriclombardot/admingenerator-generator-bundle
Installation
composer require cedriclombardot/admingenerator-generator-bundle
Add to AppKernel.php:
new CedricLombardot\AdminGeneratorBundle\AdminGeneratorBundle(),
First Configuration
Create a YAML config file (e.g., app/config/admin.yml):
admin_generator:
generation_parameters:
namespace_admin: 'AppBundle\\Admin'
namespace_entity: 'AppBundle\\Entity'
namespace_form: 'AppBundle\\Form'
namespace_repository: 'AppBundle\\Repository'
namespace_controller: 'AppBundle\\Controller'
namespace_twig: 'AppBundle\\Resources\\views'
Generate a Basic CRUD
Create a YAML file for your entity (e.g., app/config/admin/PostAdmin.yml):
PostAdmin:
entity: AppBundle\Entity\Post
list:
fields: [id, title, content, createdAt]
form:
fields: [title, content]
Run the generator:
php app/console admin:generate --entity=Post
Access the Admin Panel
Route to the generated controller (e.g., /admin/post).
UserAdmin.yml).php app/console admin:generate --entity=User.app/Resources/views/Admin/./admin/user to manage records.Define YAML Config
Use admin.yml to configure:
list.fields).form.fields).actions).filters).Generate and Customize
php app/console admin:generate --entity=Product --force
Override templates in app/Resources/views/Admin/Product/ to extend default behavior.
Integrate with Existing Code
namespace AppBundle\Admin;
use AppBundle\Admin\GeneratedProductAdmin as BaseProductAdmin;
class ProductAdmin extends BaseProductAdmin {
public function configure() {
parent::configure();
$this->menu->addLink('Custom Link', 'custom_route');
}
}
Doctrine Integration
Ensure your Entity classes are properly mapped (e.g., @ORM\Entity).
Use repository_class in YAML to override the default repository.
Twig Customization
Extend base templates (list.html.twig, edit.html.twig) by copying them to your bundle’s Resources/views/Admin/.
Routing Generate routes dynamically via YAML:
routes:
list: /admin/product/list
edit: /admin/product/edit/{id}
Validation Add custom validation rules in YAML:
form:
fields:
price:
type: money
constraints: [NotBlank, GreaterThan(0)]
YAML Syntax Errors
yaml.lint or an online validator before running the generator.Namespace Conflicts
generation_parameters.namespace_* in admin.yml match your bundle structure.--force if namespaces are misconfigured.Outdated Generator
Twig Template Overrides
php app/console cache:clear
Generator Logs
Run with -v for verbose output:
php app/console admin:generate --entity=Post -v
Doctrine Issues
Entity has proper annotations/attributes (e.g., @ORM\Table).Route Conflicts
php app/console debug:router to verify routes.Partial Generates
Use --partial to generate only specific parts (e.g., forms or controllers):
php app/console admin:generate --entity=Post --partial=form
Reuse Configs
Extend base configs with extends in YAML:
PostAdmin:
extends: BaseAdmin
entity: AppBundle\Entity\Post
Custom Actions Add actions via YAML:
actions:
custom:
label: 'Publish'
icon: 'pencil'
type: 'link'
link: 'publish_post'
role: 'ROLE_ADMIN'
Implement the action in your extended admin class.
Performance
Legacy Support
composer.json to avoid compatibility issues.How can I help you explore Laravel packages today?