Installation
composer require 20steps/autotables-bundle
Add to config/bundles.php:
return [
// ...
Twentysteps\AutoTablesBundle\TwentystepsAutoTablesBundle::class => ['all' => true],
];
Basic Configuration
Create a YAML config file (e.g., config/packages/twentysteps_autotables.yaml):
twentysteps_autotables:
default:
theme: bootstrap3
editable: true
First Use Case: Auto-Generated Table for an Entity
Annotate your entity (e.g., src/Entity/User.php):
use Twentysteps\AutoTablesBundle\Annotation\AutoTable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @AutoTable()
*/
class User
{
// ...
}
Render the Table in a Controller
use Twentysteps\AutoTablesBundle\TwentystepsAutoTablesBundle;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class UserController extends AbstractController
{
/**
* @Route("/users", name="user_list")
*/
public function listAction()
{
return $this->render('user/list.html.twig', [
'entity' => new User(),
]);
}
}
Display in Twig
{{ autotable(entity) }}
Standard CRUD Workflow
{{ autotable(entity) }} in Twig.editable: true in config and annotate columns:
/**
* @AutoTable\Column(editable=true)
*/
private $name;
actions in annotations:
/**
* @AutoTable\Action(type="delete", label="Delete")
*/
Integration with Doctrine Repositories
autotable Twig function:
{{ autotable(repository.findAll(), entity) }}
Custom CRUD Services
Twentysteps\AutoTablesBundle\Service\CrudServiceInterface and configure in services.yaml:
services:
App\Service\CustomUserCrudService:
tags: ['twentysteps_autotables.crud_service']
Theming and Styling
templates/bundles/twentystepsautotables/.twentysteps_autotables:
default:
theme: jqueryui
table_options:
paging: true
searching: true
Dynamic Column Configuration
AutoTable\Column annotations for per-property control:
/**
* @AutoTable\Column(label="Full Name", width="200px", sortable=false)
*/
private $fullName;
ManyToOne Relationships
AutoTable\ManyToOne:
/**
* @AutoTable\ManyToOne(targetEntity="App\Entity\Role", property="name")
*/
private $role;
Leverage Events
twentysteps_autotables.pre_build to modify table configuration dynamically:
use Twentysteps\AutoTablesBundle\Event\PreBuildEvent;
$eventDispatcher->addListener('twentysteps_autotables.pre_build', function (PreBuildEvent $event) {
$event->getTable()->addColumn('custom_column', 'Custom Value');
});
Custom Validation
AutoTable\Column:
/**
* @AutoTable\Column(editable=true)
* @Assert\NotBlank()
*/
private $email;
AJAX Handling
routing.yaml:
twentysteps_autotables:
resource: "@TwentystepsAutoTablesBundle/Resources/config/routing.xml"
prefix: /api
Localization
{{ autotable(entity, {'labels': {'name': 'app.user.name'}}) }}
Annotation Processing
doctrine/annotations is installed and cached:
php bin/console doctrine:cache:clear-metadata
JavaScript Conflicts
dataTablesOptions to isolate:
twentysteps_autotables:
default:
dataTablesOptions:
ajax: { url: '/api/users' }
Editable Fields and CSRF
csrf_token is included in your form templates or use editable_options:
twentysteps_autotables:
default:
editable_options:
csrf: true
ManyToOne Auto-Initialization
name or id property.property in AutoTable\ManyToOne:
/**
* @AutoTable\ManyToOne(targetEntity="App\Entity\Role", property="title")
*/
private $role;
Performance with Large Datasets
dataTablesOptions:
twentysteps_autotables:
default:
dataTablesOptions:
serverSide: true
processing: true
Check Generated HTML/JS
Enable Debug Mode
debug: true in config to log table generation:
twentysteps_autotables:
debug: true
Validate Annotations
php bin/console debug:container Twentysteps\AutoTablesBundle\Annotation\AutoTable to check if annotations are processed.Custom Column Types
Twentysteps\AutoTablesBundle\Column\AbstractColumn to create custom columns (e.g., for dates or JSON).Override Templates
templates/bundles/twentystepsautotables/table.html.twig to your project and modify as needed.Add Custom Actions
Twentysteps\AutoTablesBundle\Action\ActionInterface and register via services:
services:
App\Action\CustomAction:
tags: ['twentysteps_autotables.action']
Modify Table Configuration
twentysteps_autotables.post_build event to alter the table after generation:
$eventDispatcher->addListener('twentysteps_autotables.post_build', function (PostBuildEvent $event) {
$event->getTable()->setOption('order', [[0, 'desc']]);
});
Integrate with Forms
AutoTable\Form\Type\AutoTableType to generate forms dynamically:
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
How can I help you explore Laravel packages today?