Installation:
composer require bacon/core-bundle
Add to AppKernel.php:
new Bacon\Bundle\CoreBundle\BaconCoreBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
Configure Doctrine:
In app/config/config.yml:
doctrine:
orm:
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
Register Doctrine Listeners (app/config/services.yml):
services:
gedmo.listener.softdeleteable:
class: Gedmo\SoftDeleteable\SoftDeleteableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ "@annotation_reader" ] ]
gedmo.listener.timestampable:
class: Gedmo\Timestampable\TimestampableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ "@annotation_reader" ] ]
First Use Case:
Extend Bacon\Bundle\CoreBundle\Entity\BaseEntity for your entities:
use Bacon\Bundle\CoreBundle\Entity\BaseEntity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class User extends BaseEntity
{
// Custom fields
}
The bundle automatically adds createdAt, updatedAt, and soft-delete functionality.
BaseEntity to get createdAt, updatedAt, and deletedAt fields out-of-the-box.isDeleted() and delete() methods for soft-deletion logic:
$user = $entityManager->find(User::class, 1);
$user->delete(); // Soft-deletes the record
Bacon\Bundle\CoreBundle\Form\FormHandler to simplify CRUD operations:
use Bacon\Bundle\CoreBundle\Form\FormHandler;
$formHandler = new FormHandler($form, $entityManager);
if ($formHandler->save()) {
// Success
}
KnpPaginatorBundle for pagination:
use Knp\Component\Pager\PaginatorInterface;
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$entityManager->getRepository(User::class)->findAll(),
$request->query->getInt('page', 1),
10
);
{{ entity.createdAt|date('Y-m-d') }}
{% if entity.isDeleted() %}Deleted{% endif %}
Soft-Delete Filter:
softdeleteable filter is enabled in config.yml; otherwise, soft-deleted records may still appear in queries.FormHandler Quirks:
FormHandler assumes the form is bound to an entity. Unbound forms may throw errors.isDeleted()) before saving to avoid conflicts.Entity Inheritance:
BaseEntity methods (e.g., prePersist()) carefully to avoid breaking automatic timestamp updates.stderr logging to debug Doctrine listeners:
# config.yml
doctrine:
dbal:
logging: true
AND u.deletedAt IS NULL manually to queries if soft-delete filter isn’t working.Custom Behaviors:
Add new behaviors by extending BaseEntity and overriding methods:
class AuditEntity extends BaseEntity
{
public function prePersist()
{
$this->setCreatedBy($this->getUser());
parent::prePersist();
}
}
Twig Extensions:
Extend existing Twig filters in Resources/twig/ or override the bundle’s extensions.
FormHandler:
Subclass FormHandler to add custom validation or pre-save logic:
class CustomFormHandler extends FormHandler
{
public function save()
{
if (!$this->validateCustomRules()) {
return false;
}
return parent::save();
}
}
How can I help you explore Laravel packages today?