Générateur
Référence complète de php bin/dt_generate
Syntaxe
php bin/dt_generate <table> champ:type [champ:type ...]
| Paramètre | Description |
|---|---|
<table> | Nom de la table en base (pluriel, snake_case). Ex : articles, blog_posts |
champ:type | Un ou plusieurs champs. Chaque champ génère une colonne dans la migration et un input dans les formulaires. |
Types de champs
| Type | SQL généré | Formulaire généré |
|---|---|---|
string | VARCHAR(255) | Inline_input type="text" |
text | TEXT | <textarea> |
int | INT | Inline_input type="number" |
bool | TINYINT(1) DEFAULT 0 | Inline_select (0/1) |
date | DATE | Inline_input type="date" |
datetime | DATETIME | Inline_input type="datetime-local" |
select | VARCHAR(50) | Inline_select (à remplir manuellement) |
Exemple complet
php bin/dt_generate products name:string price:int category:select stock:int active:bool
Résultat :
✓ app/Controllers/Admin/Products_ctrl.php
✓ app/views/admin/products/index.php
✓ app/views/admin/products/edit.php
✓ app/views/admin/products/_dt.php
✓ app/views/admin/products/_row.php
✓ app/views/admin/products/_row_edit.php
✓ app/views/admin/products/_modal_create.php
✓ app/views/admin/products/_modal_edit.php
✓ app/views/admin/products/_modal_del.php
✓ migrations/2024_01_15_products.php
→ Ajoutez dans roads.php :
$router->scan_controller(\App\Controllers\Admin\Products_ctrl::class);
Conventions de nommage
| Élément | Convention | Exemple (table: products) |
|---|---|---|
| Table DB | Pluriel, snake_case (fourni tel quel) | products |
| Entity (variable) | Singulier (singularize auto) | $product |
| Classe Controller | ucfirst(table) . '_ctrl' | Products_ctrl |
| Préfixe route | admin/{table} | admin/products |
| Dossier vues | admin/{table}/ | admin/products/ |
| Nom de route | admin.{table} | admin.products |
Fichiers générés — détail
Controller —
Admin/{Table}_ctrl.php#[Route_prefix]avec préfixeadmin/{table}+ middleware Role_middleware ':admin'#[Route]surdt_page()(GET, chemin vide)- Classe
Validatorinline pour store/update - Propriétés
$table,$entity,$road,$view_dirpré-remplis
index.php — Page principale
Fenêtre start-window avec toolbar (bouton create), include
_dt.php.
_dt.php — Table + pagination
Onglets actif/corbeille, barre de recherche, table avec headers triables, boucle
_row.php, pagination, bulk bar, #modal-container.
_row.php — Ligne normale
<tr> avec dblclick → inline edit, colonnes auto-générées, checkbox bulk, boutons corbeille/restore/delete.
_row_edit.php — Ligne en édition inline
Inputs inline pour chaque champ, boutons save/cancel. Dépendances
use directes (Inline_input, Inline_select, Inline_cancel_btn).
_modal_create.php et _modal_edit.php
Modales Bootstrap avec
modal_form() htmx, inputs pour chaque champ, affichage des erreurs.
_modal_del.php — Confirmation suppression
Modale de confirmation avec bouton suppression définitive.
edit.php — Page d'édition dédiée
Page complète avec
form() htmx-boost, champs, back_btn.
Migration —
migrations/{date}_{table}.php
Table SQL avec
id, champs générés, status (0=actif, -1=corbeille), created_at, updated_at.
Gotchas post-génération
Heritage htmx : Si une méthode héritée de
Dt_controller est overridée dans le controller concret,
re-déclarer l'attribut #[Route] — les attributs de la classe abstraite ne sont pas vus automatiquement.
Type
select : Les options du select ne sont pas devinables par le générateur.
Après génération, remplissez le tableau d'options dans _row_edit.php et les modales.