Install Dependencies
Run composer require culabs/admin-bundle:2.6.*@dev and update vendors:
composer update --prefer-dist
Register Bundles
Add the required bundles to app/AppKernel.php:
new CULabs\AdminBundle\CULabsAdminBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new Lexik\Bundle\FormFilterBundle\LexikFormFilterBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
Configure Twig
Set the default form theme in config.yml:
twig:
form:
resources:
- bootstrap_3_horizontal_layout.html.twig
Generate a CRUD Controller Use the bundle’s command to scaffold a CRUD interface:
php app/console culabs:admin:generate:crud --entity=YourEntity --bundle=YourBundle
Define Backend Menu
Create app/config/menu.yml to structure your admin navigation:
menu.backend:
items:
your_entity:
label: Your Entity
uri: path/to/your_entity
Import Menu Config
Add to config.yml:
imports:
- { resource: menu.yml }
Clear Cache Run:
php app/console cache:clear
Generate a CRUD for a User entity:
php app/console culabs:admin:generate:crud --entity=User --bundle=AppBundle
This creates:
UserAdminController) with index, create, edit, and delete actions.LexikFormFilterBundle).KnpPaginatorBundle).KnpMenuBundle).CRUD Generation
culabs:admin:generate:crud for rapid scaffolding.Resources/views/ of your bundle.configure()) to add logic:
public function configure()
{
parent::configure();
$this->add('custom_field', 'text');
}
Form Customization
$this->add('custom_field', 'AppBundle\Form\Type\CustomFieldType');
LexikFormFilterBundle for dynamic filtering:
# config.yml
lexik_form_filter:
form_types:
- AppBundle\Form\Type\YourEntityFilterType
Menu Management
menu.yml:
menu.backend:
items:
dashboard:
label: Dashboard
uri: '#'
children:
users:
label: Users
uri: path/to/users
{{ knp_menu_render('menu.backend', { 'depth': 2 }) }}
Pagination
KnpPaginatorBundle for pagination in listings:
$paginator = $this->get('knp_paginator');
$results = $paginator->paginate(
$this->getDoctrine()->getRepository('AppBundle:User')->findAll(),
$this->get('request')->query->get('page', 1),
10
);
return $this->render('AppBundle:UserAdmin:index.html.twig', ['results' => $results]);
Entity-Specific Logic
public function preUpdateAction($id)
{
// Custom logic before update
}
Doctrine Integration Ensure your entity is properly mapped with Doctrine and has a repository class.
Security
Protect admin routes in security.yml:
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
Asset Management Use Symfony’s asset system for CSS/JS:
{% block stylesheets %}
{{ parent() }}
{{ asset('bundles/culabsadmin/css/admin.css') }}
{% endblock %}
Translation
Extend translations in translations/messages.en.yml:
'Your Entity': 'Your Entity Label'
Bundle Compatibility
LexikFormFilterBundle, KnpPaginatorBundle) must be compatible with your Symfony version.Menu Configuration
menu.yml in config.yml will break navigation.menu.yml keys (e.g., items) will cause silent failures.Form Theme Overrides
bootstrap_3_horizontal_layout.html.twig is missing, forms will render without styling.vendor/culabs/admin-bundle/Resources/views/Form/ or override it in your bundle.Command Output
generate:crud command may overwrite existing files. Backup your Resources/ directory first.Pagination Issues
KnpPaginatorBundle is registered before CULabsAdminBundle in AppKernel.php.Check Generated Files
generate:crud, inspect:
src/YourBundle/Controller/YourEntityAdminController.phpResources/views/YourEntityAdmin/Resources/config/routing.ymlSymfony Debug Toolbar
Log Errors
app/config/config_dev.yml:
framework:
router:
resource: "%kernel.root_dir%/config/routing_dev.yml"
strict_requirements: true
profiler: { only_exceptions: false }
Customize Templates
Override bundle templates by creating a CULabsAdminBundle directory in your bundle’s Resources/:
YourBundle/
Resources/
CULabsAdminBundle/
views/
YourEntityAdmin/
index.html.twig
Add Custom Actions Extend the controller to add actions (e.g., bulk delete):
public function bulkDeleteAction()
{
$ids = $this->get('request')->request->get('ids');
// Logic to delete entities
return $this->redirect($this->generateUrl('admin_users'));
}
Use Events
Listen to bundle events (e.g., culabs.admin.entity.pre_save) for pre/post-processing:
services:
app.admin.listener:
class: AppBundle\EventListener\AdminListener
tags:
- { name: kernel.event_listener, event: culabs.admin.entity.pre_save, method: onPreSave }
Performance
@ORM\Cache(usage="READ_WRITE") to entities for heavy CRUD operations.->select() in repository queries to limit loaded fields.Testing
php app/console culabs:admin:generate:crud --entity=TestEntity --bundle=AppBundle --test
$this->container->set('culabs_admin.templating.helper', $this->createMock('CULabs\AdminBundle\Templating\Helper\AdminHelper'));
How can I help you explore Laravel packages today?