Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Userbundle Laravel Package

alpixel/userbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require alpixel/userbundle:~2.0
    

    Ensure compatibility with your Symfony version (2.8+ or 3.0).

  2. Register the Bundle Add to AppKernel.php:

    new Alpixel\Bundle\UserBundle\AlpixelUserBundle(),
    
  3. Create a Custom User Entity Extend BaseUser in your AppBundle:

    namespace AppBundle\Entity;
    use Alpixel\Bundle\UserBundle\Entity\User as BaseUser;
    
    class User extends BaseUser { /* ... */ }
    
  4. Update Database Schema

    php app/console doctrine:schema:update --force
    
  5. Add Routing Include in app/config/routing.yml:

    admin:
        resource: '@AlpixelUserBundle/Resources/config/routing.yml'
    
  6. Configure Security (Optional) Override security.yml if using multiple firewalls. Copy from the bundle’s Resources/config/security.yml and customize.


First Use Case: Admin User Creation

  1. Load Fixtures The bundle includes fixtures for admin users. Run:

    php app/console doctrine:fixtures:load --no-interaction
    

    (Ensure AlpixelUserBundle fixtures are enabled in app/config/config.yml.)

  2. Access Admin Panel Navigate to /admin (default route). Use the pre-created admin credentials (check fixtures for defaults).


Implementation Patterns

Workflow: Extending User Functionality

  1. Custom Fields Add fields to your User entity (e.g., role, profilePicture):

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $profilePicture;
    

    Update the BaseUser abstract class if shared across projects.

  2. Sonata Admin Integration Extend AlpixelUserBundle's admin class for Sonata:

    namespace AppBundle\Admin;
    use Alpixel\Bundle\UserBundle\Admin\UserAdmin as BaseUserAdmin;
    
    class UserAdmin extends BaseUserAdmin { /* ... */ }
    

    Register in services.yml:

    services:
        app.admin.user:
            class: AppBundle\Admin\UserAdmin
            tags:
                - { name: sonata.admin, manager_type: orm, group: "Users", label: "User" }
    
  3. Custom Login Templates Override templates in app/Resources/AlpixelUserBundle/views/admin/:

    alpixel_user:
        firewall_templates:
            admin:
                login_template: 'AlpixelUserBundle:admin:custom_login.html.twig'
    
  4. Dynamic Firewall Configuration Use the alpixel_user.firewall_templates parameter to customize login pages per firewall:

    alpixel_user:
        firewall_templates:
            api:
                login_template: 'AlpixelUserBundle:api:login.html.twig'
    

Integration Tips

  • FOSUserBundle Compatibility: Leverage FOSUserBundle’s features (e.g., UserManager, UserInterface) via BaseUser. Example:

    $userManager = $this->get('fos_user.user_manager');
    $user = $userManager->createUser();
    
  • Sonata Admin Customization: Override Sonata templates for the admin panel (e.g., edit.html.twig) in your theme.

  • Fixtures: Extend AlpixelUserBundle\DataFixtures\ORM\LoadUserData to add custom fixtures:

    class LoadCustomUserData extends LoadUserData {
        public function load(ObjectManager $manager) {
            parent::load($manager);
            // Add custom users...
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated FOSUserBundle Version: The bundle targets FOSUserBundle ~1.3 or ~2.0. Ensure your composer.json aligns:

    "friendsofsymfony/user-bundle": "^2.0"
    

    If using FOSUserBundle 3.x, fork the bundle or patch compatibility.

  2. Schema Updates: Running doctrine:schema:update without --force may fail if the BaseUser schema changes. Backup your database first.

  3. Sonata Admin Conflicts: If Sonata Admin is not loaded, the admin routes may break. Ensure SonataAdminBundle is registered before AlpixelUserBundle.

  4. Fixtures Overwriting: Default fixtures create an admin user with hardcoded credentials (admin/admin). Override in LoadUserData or disable fixtures:

    # app/config/config.yml
    alpixel_user:
        fixtures: false
    

Debugging

  1. Routing Issues: Clear cache and check routes:

    php app/console cache:clear
    php app/console debug:router | grep admin
    
  2. Template Overrides: Verify template paths. Use Symfony’s debug toolbar to confirm template inheritance.

  3. Firewall Configuration: If login fails, check security.yml for correct firewall names and template paths:

    firewalls:
        admin:
            pattern: ^/admin
            form_login:
                template: 'AlpixelUserBundle:admin:pages/back_login.html.twig'
    

Extension Points

  1. Custom User Events: Listen to FOSUserBundle events (e.g., fos_user.registered) to extend logic:

    services:
        app.user.event_listener:
            class: AppBundle\EventListener\UserListener
            tags:
                - { name: kernel.event_listener, event: fos_user.registered, method: onUserRegistered }
    
  2. Dynamic Login Styling: Override CSS/JS in your theme by extending the bundle’s assets:

    {# app/Resources/public/css/admin.css #}
    .alpixel-login { /* Custom styles */ }
    
  3. Multi-Tenant Support: Extend BaseUser to add tenant-specific fields (e.g., tenantId) and filter queries in repositories.

  4. API Integration: Use the api firewall template to create a lightweight login endpoint for SPAs:

    alpixel_user:
        firewall_templates:
            api:
                login_template: 'AlpixelUserBundle:api:login.json.twig'
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware