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

Atk4 Symfony Bundle Laravel Package

abbadon1334/atk4-symfony-bundle

Symfony 6 bundle integrating ATK4 UI/Data. Installs bundle config and public assets, adds a models:rebuild console command for dev DB rebuilds, and lets you build ATK4-powered controllers easily via #[Atk4Controller] with Symfony DI and routing.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require abbadon1334/atk4-symfony-bundle:"*"
    

    Ensure minimum-stability is set to dev in composer.json:

    "config": {
        "minimum-stability": "dev"
    }
    
  2. First Use Case:

    • Run the database rebuild command to scaffold models from your src/Models directory:
      bin/console models:rebuild -p src/Models
      
    • Verify the public/ folder contains ATK4 assets (JS/CSS) after installation.
  3. Quick Controller: Create a basic ATK4-powered Symfony controller in src/Controller/:

    use Atk4\Symfony\Module\Atk4App;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Atk4\Ui\Header;
    
    #[Atk4Controller]
    class Homepage extends AbstractController
    {
        public function __construct(protected Atk4App $atk4app) {}
    
        #[Route('/', name: 'homepage')]
        public function index(): Response
        {
            $app = $this->atk4app->getApp();
            $app->initLayout([Centered::class]);
            Header::addTo($app, ['Demo']);
            return $app->run();
        }
    }
    

Implementation Patterns

Core Workflow

  1. Model-Driven Development:

    • Define models in src/Models/ (e.g., User.php).
    • Rebuild the database schema via:
      bin/console models:rebuild -p src/Models
      
    • Use ATK4’s Model class for CRUD operations:
      $user = new User($this->atk4app->getDb());
      $user->add(['name' => 'John']);
      
  2. Controller Integration:

    • Attribute-Based Routing: Use #[Atk4Controller] to auto-register controllers.
    • Dependency Injection: Inject Atk4App for app initialization and Security for auth:
      public function __construct(protected Atk4App $atk4app, protected Security $security) {}
      
    • Layout Management: Use initLayout() to define UI structure:
      $app->initLayout([TopMenu::class, Centered::class]);
      
  3. UI Components:

    • Leverage ATK4’s UI classes (e.g., Grid, Form, Header) within controllers:
      $grid = new Grid($app, 'users', $user);
      $grid->addColumn('name');
      $grid->addColumn('email');
      
  4. Event Handling:

    • Bind Symfony events to ATK4 actions:
      $this->atk4app->on('init', function() {
          // Initialize ATK4-specific logic
      });
      
  5. Asset Management:

    • ATK4 assets (JS/CSS) are auto-installed to public/atk4/. Include them in your base template:
      <link rel="stylesheet" href="{{ asset('atk4/css/atk4.css') }}">
      

Gotchas and Tips

Pitfalls

  1. Database Rebuild:

    • Running models:rebuild drops and recreates your database. Backup first!
    • Only use in development. For production, manually migrate models or use ATK4’s migrate() method.
  2. Attribute Routing:

    • Forgetting #[Atk4Controller] on a controller class won’t auto-register it. Manually add to config/bundles.php if needed:
      return [
          // ...
          Atk4\Symfony\Atk4SymfonyBundle::class => ['all' => true],
      ];
      
  3. Symfony-ATK4 Context Switching:

    • ATK4 uses zero-config routing by default. If you mix Symfony routes (#[Route]), ensure they don’t conflict with ATK4’s dynamic routing.
  4. Dependency Injection:

    • ATK4 services (e.g., Db, App) aren’t autowired by Symfony’s DI container. Always inject Atk4App explicitly.
  5. Asset Paths:

    • ATK4 assets are not versioned by default. For production, configure Symfony’s asset versioning:
      # config/packages/twig.yaml
      twig:
          paths: { '%kernel.project_dir%/public/atk4': atk4 }
      

Debugging Tips

  1. Check ATK4 Logs:

    • Enable ATK4 debugging in config/packages/atk4_symfony.yaml:
      atk4_symfony:
          debug: true
      
    • Logs appear in Symfony’s var/log/dev.log.
  2. Database Schema Issues:

    • If models:rebuild fails, inspect the generated SQL in var/log/doctrine.log.
  3. Controller Lifecycle:

    • ATK4 controllers extend Symfony’s AbstractController, so Symfony’s Request/Response lifecycle applies. Use return $app->run(); to render ATK4 output.
  4. UI Rendering:

    • If UI components (e.g., Grid) don’t render, verify:
      • The component is added to the app ($app->add($grid)).
      • The app’s layout is initialized (initLayout()).

Extension Points

  1. Custom Model Events:

    • Extend ATK4’s Model class to hook into Symfony events:
      use Symfony\Component\HttpKernel\Event\ControllerEvent;
      
      $this->atk4app->on('kernel.controller', function(ControllerEvent $event) {
          if ($event->getController() instanceof YourController) {
              // Custom logic
          }
      });
      
  2. Override ATK4 Templates:

    • Copy ATK4’s Twig templates from vendor/atk4/atk4-ui/src/Resources/views/ to templates/atk4/ to customize them.
  3. Integrate with Symfony Forms:

    • Use ATK4’s Form class alongside Symfony’s FormBuilder for hybrid forms:
      $form = $this->createFormBuilder()
          ->add('name', TextType::class)
          ->getForm();
      $atk4Form = new Atk4\Form($app, $form->createView());
      
  4. Authentication:

    • Combine ATK4’s Auth with Symfony’s Security component:
      if (!$this->security->isGranted('ROLE_USER')) {
          $this->atk4app->auth->loginRequired();
      }
      
  5. CLI Commands:

    • Extend the bundle’s commands (e.g., models:rebuild) by creating custom commands in src/Command/:
      use Symfony\Component\Console\Command\Command;
      use Symfony\Component\Console\Input\InputInterface;
      use Symfony\Component\Console\Output\OutputInterface;
      
      class CustomAtk4Command extends Command
      {
          protected function execute(InputInterface $input, OutputInterface $output): int
          {
              $this->atk4app->getDb()->query("CUSTOM SQL");
              return Command::SUCCESS;
          }
      }
      
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.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver