Installation Add the bundle to your Symfony 2 project via Composer:
composer require culabs/contact-bundle
Register the bundle in app/AppKernel.php:
new CULabs\ContactBundle\CULabsContactBundle(),
Database Setup
Run migrations (if provided) or manually create tables based on the bundle’s schema (check Resources/doc/ for details). Example table structure:
CREATE TABLE contacts (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255),
phone VARCHAR(50),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
Basic CRUD via Controller
Inject the bundle’s service (e.g., contact.manager) and use its methods:
use CULabs\ContactBundle\Manager\ContactManager;
class ContactController extends Controller {
public function index(ContactManager $manager) {
$contacts = $manager->findAll();
return $this->render('contact/index.html.twig', ['contacts' => $contacts]);
}
}
First Form Use the bundle’s form type (if available) in a Twig template:
{{ form_start(form) }}
{{ form_widget(form.name) }}
{{ form_widget(form.email) }}
{{ form_widget(form.phone) }}
{{ form_end(form) }}
Contact Management
contact.manager->create($data).find($id) and update fields, then save().contact.manager->delete($id).Integration with Forms
use CULabs\ContactBundle\Form\Type\ContactType;
$form = $this->createForm(ContactType::class, $contact);
API Endpoints (RESTful)
JsonResponse or FOSRestBundle to expose CRUD:
public function getContact(ContactManager $manager, $id) {
return new JsonResponse($manager->find($id));
}
Event Listeners
contact.pre_save) for pre-processing:
services:
app.contact_listener:
class: AppBundle\EventListener\ContactListener
tags:
- { name: kernel.event_listener, event: contact.pre_save, method: onPreSave }
Batch Operations
EntityManager or bundle methods for bulk actions:
$manager->deleteByEmail('old@example.com');
Lack of Documentation
Manager/, Resources/config/, and Entity/ directories for clues.Doctrine Integration Assumptions
Form Type Coupling
ContactType is tightly coupled to its entity, extending it may require overriding methods.class CustomContactType extends ContactType {
public function buildForm(FormBuilderInterface $builder, array $options) {
parent::buildForm($builder, $options);
$builder->add('custom_field', TextType::class);
}
}
Translation Strings
{{ 'contact.name'|trans }}
No Built-in API
# config/packages/dev/doctrine.yaml
doctrine:
dbal:
logging: true
$eventDispatcher->addListener('contact.pre_save', function($event) {
dump($event->getContact());
});
Custom Fields Add fields to the entity and update the form type:
// src/Entity/Contact.php
/**
* @ORM\Column(type="string", nullable=true)
*/
private $customField;
Validation Groups Use Symfony’s validation groups for partial updates:
$contact->setEmail('new@example.com');
$validator->validate($contact, ['PATCH']);
Custom Repositories Extend the bundle’s repository for complex queries:
class CustomContactRepository extends ServiceEntityRepository {
public function findByActive() {
return $this->createQueryBuilder('c')
->where('c.is_active = :active')
->setParameter('active', true)
->getQuery()
->getResult();
}
}
Override Templates
Copy bundle templates from vendor/culabs/contact-bundle/Resources/views/ to templates/bundles/culabscontact/ to customize without modifying the original.
Configuration Overrides
Override bundle parameters in config/packages/culabs_contact.yaml:
culabs_contact:
default_per_page: 20
allowed_fields: ['name', 'email', 'phone', 'custom_field']
How can I help you explore Laravel packages today?