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.
Installation:
composer require abbadon1334/atk4-symfony-bundle:"*"
Ensure minimum-stability is set to dev in composer.json:
"config": {
"minimum-stability": "dev"
}
First Use Case:
src/Models directory:
bin/console models:rebuild -p src/Models
public/ folder contains ATK4 assets (JS/CSS) after installation.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();
}
}
Model-Driven Development:
src/Models/ (e.g., User.php).bin/console models:rebuild -p src/Models
Model class for CRUD operations:
$user = new User($this->atk4app->getDb());
$user->add(['name' => 'John']);
Controller Integration:
#[Atk4Controller] to auto-register controllers.Atk4App for app initialization and Security for auth:
public function __construct(protected Atk4App $atk4app, protected Security $security) {}
initLayout() to define UI structure:
$app->initLayout([TopMenu::class, Centered::class]);
UI Components:
Grid, Form, Header) within controllers:
$grid = new Grid($app, 'users', $user);
$grid->addColumn('name');
$grid->addColumn('email');
Event Handling:
$this->atk4app->on('init', function() {
// Initialize ATK4-specific logic
});
Asset Management:
public/atk4/. Include them in your base template:
<link rel="stylesheet" href="{{ asset('atk4/css/atk4.css') }}">
Database Rebuild:
models:rebuild drops and recreates your database. Backup first!migrate() method.Attribute Routing:
#[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],
];
Symfony-ATK4 Context Switching:
#[Route]), ensure they don’t conflict with ATK4’s dynamic routing.Dependency Injection:
Db, App) aren’t autowired by Symfony’s DI container. Always inject Atk4App explicitly.Asset Paths:
# config/packages/twig.yaml
twig:
paths: { '%kernel.project_dir%/public/atk4': atk4 }
Check ATK4 Logs:
config/packages/atk4_symfony.yaml:
atk4_symfony:
debug: true
var/log/dev.log.Database Schema Issues:
models:rebuild fails, inspect the generated SQL in var/log/doctrine.log.Controller Lifecycle:
AbstractController, so Symfony’s Request/Response lifecycle applies. Use return $app->run(); to render ATK4 output.UI Rendering:
Grid) don’t render, verify:
$app->add($grid)).initLayout()).Custom Model Events:
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
}
});
Override ATK4 Templates:
vendor/atk4/atk4-ui/src/Resources/views/ to templates/atk4/ to customize them.Integrate with Symfony Forms:
Form class alongside Symfony’s FormBuilder for hybrid forms:
$form = $this->createFormBuilder()
->add('name', TextType::class)
->getForm();
$atk4Form = new Atk4\Form($app, $form->createView());
Authentication:
Auth with Symfony’s Security component:
if (!$this->security->isGranted('ROLE_USER')) {
$this->atk4app->auth->loginRequired();
}
CLI Commands:
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;
}
}
How can I help you explore Laravel packages today?