codeconsortium/ccdn-user-admin-bundle
Installation Add the bundle via Composer:
composer require codeconsortium/ccdn-user-admin-bundle
Register the bundle in app/AppKernel.php:
new CodeConsortium\CCDNUserAdminBundle\CCDNUserAdminBundle(),
First Use Case: Basic User Management
/admin (default route, verify in routing.yml).User entity out-of-the-box. Check src/Resources/config/routing.yml for routes.Configuration
Override default settings in app/config/config.yml:
ccdn_user_admin:
# Example: Customize user class or admin routes
user_class: AppBundle\Entity\User
admin_route_prefix: /custom-admin
Entity Setup
Ensure your User entity extends the base class provided by the bundle (if applicable). Example:
use CodeConsortium\CCDNUserAdminBundle\Entity\User as BaseUser;
class User extends BaseUser
{
// Custom fields/methods
}
Extending User Fields
Add custom fields to the User entity and update the admin form:
// In User entity
/**
* @ORM\Column(type="string", length=255)
*/
private $customField;
// Getter/Setter
Override the admin form type in AppBundle/Resources/config/admin.yml:
ccdn_user_admin:
form:
fields:
- { name: customField, type: text }
Customizing Admin Routes
Extend or replace routes in app/config/routing.yml:
ccdn_user_admin:
resource: "@CCDNUserAdminBundle/Resources/config/routing.yml"
prefix: /admin
options:
expose: true
Event Listeners/Subscribers
Hook into user lifecycle events (e.g., prePersist, postUpdate):
// src/AppBundle/EventListener/UserListener.php
use CodeConsortium\CCDNUserAdminBundle\Event\UserEvents;
class UserListener
{
public function onUserPrePersist(UserEvent $event)
{
$user = $event->getUser();
$user->setCustomField('default_value');
}
}
Register the listener in services.yml:
services:
app.user_listener:
class: AppBundle\EventListener\UserListener
tags:
- { name: kernel.event_listener, event: ccdn.user.pre_persist, method: onUserPrePersist }
Integration with Security Use the bundle’s authentication logic or extend it:
# app/config/security.yml
security:
providers:
ccdn_user_provider:
id: ccdn_user_admin.user_provider
firewalls:
admin:
pattern: ^/admin
form_login:
provider: ccdn_user_provider
User entity with DoctrineFixturesBundle for seeding:
$user = new User();
$user->setUsername('test');
$user->setEmail('test@example.com');
$manager->persist($user);
// src/AppBundle/DTO/UserDTO.php
class UserDTO extends BaseDTO
{
public function getCustomField() { /* ... */ }
}
translations/messages.en.yml:
ccdn_user_admin:
user:
label: "Custom User Label"
Symfony 2.4 Dependency
Missing Documentation
grep -r "class " src/
to explore the bundle’s structure.Route Conflicts
/admin) may clash with other bundles. Always check:
php app/console router:debug
Entity Inheritance
User entity, ensure all required methods (e.g., getRoles()) are implemented. The base class may enforce abstract methods.Form Validation
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\NotBlank()
*/
private $customField;
Enable Debug Mode
Set APP_DEBUG=true in .env or app/config/parameters.yml to see detailed errors.
Check Events Verify event listeners are registered:
php app/console debug:event-dispatcher
Database Schema Compare your schema with the bundle’s migrations (if provided) using:
php app/console doctrine:schema:validate
Log Admin Actions Enable monolog for the admin bundle:
# app/config/config.yml
monolog:
handlers:
admin:
type: stream
path: "%kernel.logs_dir%/admin.log"
level: debug
channels: ["ccdn_user_admin"]
Custom Admin Controllers Override the default admin controller by extending the bundle’s controller:
// src/AppBundle/Controller/AdminController.php
use CodeConsortium\CCDNUserAdminBundle\Controller\AdminController as BaseAdminController;
class AdminController extends BaseAdminController
{
public function customAction()
{
// ...
}
}
Update routing to point to your controller.
Twig Extensions Add custom Twig filters/functions for admin templates:
// src/AppBundle/Twig/AppExtension.php
class AppExtension extends \Twig_Extension
{
public function getFilters()
{
return [
new \Twig_SimpleFilter('custom_filter', [$this, 'customFilter']),
];
}
}
API Endpoints
Create a custom API controller to interact with the User entity:
// src/AppBundle/Controller/UserAPIController.php
use FOS\RestBundle\Controller\FOSRestController;
class UserAPIController extends FOSRestController
{
public function getUsersAction()
{
$users = $this->getDoctrine()->getRepository('CCDNUserAdminBundle:User')->findAll();
return $this->handleView($this->view($users, 200));
}
}
Testing Use PHPUnit to test admin functionality:
// tests/AppBundle/Controller/AdminControllerTest.php
public function testUserCreation()
{
$client = static::createClient();
$crawler = $client->request('GET', '/admin/user/new');
$this->assertTrue($crawler->filter('h1:contains("New User")')->count() > 0);
}
$this->container->getParameter('ccdn_user_admin.admin_route_prefix');
php app/console debug:config ccdn_user_admin
How can I help you explore Laravel packages today?