azwhosting/spark-crud-generator

🚀 Interactive CRUD generator for CodeIgniter 4 — multilingual, smart CLI prompts, safe overwrites, and full CRUD stack (model, entity, controller, views, migration).

v1.1.0 2025-05-06 20:06 UTC

This package is auto-updated.

Last update: 2025-05-06 20:40:03 UTC


README

Version License PHP CI4 Compatible

Choose your language / Choisissez votre langue :

🇬🇧 English version

📚 Table of Contents

✹ Features

  • Generates Model, Entity, Controller, Views, Migration
  • Interactive prompts for field definitions
  • Language support (English & French)
  • No file overwrite without confirmation
  • --force mode to skip confirmations
  • Clean structure: templates and CRUD folders
  • Auto migration execution prompt
  • Routes summary automatically displayed after generation
  • Direct clickable link to CRUD interface
  • Full entity support with Entity as object (no array access)
  • Supports template themes (e.g., default, bootstrap, etc.)
  • Modular architecture with dedicated classes per generator (model, controller, views, etc.)
  • All code is rendered from .tpl files for full customization
  • Header and footer layout support via layout templates
  • Detects missing routes and optionally injects them into Routes.php

⚙ Installation

Using Composer (recommended)

composer require azwhosting/spark-crud-generator --dev

Then publish the language files:

php spark crud:publish-lang

⚙ Manual Installation

You can install the generator manually if you don't use Composer.

Manual installation steps:

  1. Place the following files in your project:
app/Commands/MakeCrud.php
app/Language/en/CrudGenerator.php
app/Language/fr/CrudGenerator.php

📌 Create the folders if they don’t exist.

  1. Run the generator from the Spark CLI:
php spark make:crud
  1. Follow the interactive prompts to generate your CRUD.

You can now call it via Spark CLI.

🚀 Usage

php spark make:crud

Follow the prompts:

  • Entity name
  • Add fields one by one
  • File creation with overwrite protection

Example:

php spark make:crud Product

đŸ§© Custom Templates

You can define your own generation theme by duplicating the default templates:

  1. Copy the folder resources/templates/default/ into a new folder resources/templates/your-theme/
  2. Customize any .tpl file (controller, model, views, etc.)
  3. Run php spark make:crud and select your theme when prompted

Templates use placeholders like {{entity}}, {{fields}}, {{formFields}}, etc.

🔄 Automatic Route Injection

After generation, the system offers to automatically inject routes into app/Config/Routes.php.

  • If routes already exist, they will be skipped.
  • If missing, the lines from route.tpl will be inserted after confirmation.
  • A backup of Routes.php is automatically created before any modification.
  • Manual fallback is always shown in case of conflict or refusal.

You can customize the injected routes by editing the route.tpl file inside your selected template.

📄 Options

Option Description
--force or -f Force overwrite without any confirmation

🌍 Localization

Language files are located in:

app/Language/en/CrudGenerator.php
app/Language/fr/CrudGenerator.php

You can edit them or create your own translations.

📁 Generated Structure

app/
├── Controllers/
│   └── ProductController.php
├── Entities/
│   └── Product.php
├── Models/
│   └── ProductModel.php
├── Views/
│   ├── product/
│   │   ├── index.php
│   │   ├── create.php
│   │   ├── edit.php
│   │   └── show.php
│   └── templates/
│       ├── header.php
│       └── footer.php
├── Database/
│   └── Migrations/
│       └── 2025-01-01-CreateProductTable.php

đŸ›Ąïž Safeguards

  • Checks if CRUD already exists
  • Warns if a table already exists in DB
  • Asks before overwriting any file
  • Bypass everything with --force

📝 License

MIT License — Free to use, modify, share.

đŸ‡«đŸ‡· Version française

📚 Sommaire

✹ FonctionnalitĂ©s

  • GĂ©nĂšre ModĂšle, EntitĂ©, ContrĂŽleur, Vues, Migration
  • Interface interactive pour les champs
  • Prise en charge de plusieurs langues (FR / EN)
  • Aucun fichier Ă©crasĂ© sans confirmation
  • Mode --force pour tout passer en force
  • Structure claire : templates et vues par entitĂ©
  • Suggestion d'exĂ©cution automatique de la migration
  • RĂ©capitulatif complet des routes Ă  ajouter
  • Lien cliquable direct vers l'interface CRUD gĂ©nĂ©rĂ©e
  • Support complet des entitĂ©s sous forme d'objets (plus d'accĂšs tableau)
  • Prise en charge des thĂšmes de templates (ex. : default, bootstrap, etc.)
  • Architecture modulaire avec une classe dĂ©diĂ©e par gĂ©nĂ©rateur (modĂšle, contrĂŽleur, vues, etc.)
  • Tout le code est gĂ©nĂ©rĂ© Ă  partir de fichiers .tpl entiĂšrement personnalisables
  • Gestion des layouts header et footer via des templates dĂ©diĂ©s
  • DĂ©tection des routes manquantes et injection automatique optionnelle dans Routes.php

⚙ Installation

Via Composer (recommandé)

composer require azwhosting/spark-crud-generator --dev

Puis publiez les fichiers de langue :

php spark crud:publish-lang

⚙ Installation manuelle

Vous pouvez installer le générateur manuellement si vous n'utilisez pas Composer.

Étapes pour une installation manuelle :

  1. Placez les fichiers suivants dans votre projet :
app/Commands/MakeCrud.php
app/Language/en/CrudGenerator.php
app/Language/fr/CrudGenerator.php

📌 CrĂ©ez les dossiers s'ils n'existent pas.

  1. Lancez le générateur depuis le terminal Spark :
php spark make:crud
  1. Suivez les instructions interactives pour générer le CRUD.

đŸ§© Templates personnalisĂ©s

Vous pouvez définir votre propre thÚme de génération en dupliquant les templates par défaut :

  1. Copiez le dossier resources/templates/default/ vers un nouveau dossier resources/templates/votre-theme/
  2. Personnalisez les fichiers .tpl (contrĂŽleur, modĂšle, vues, etc.)
  3. Lancez la commande php spark make:crud et sĂ©lectionnez votre thĂšme lorsqu’il est proposĂ©

Les templates utilisent des balises comme {{entity}}, {{fields}}, {{formFields}}, etc.

🔄 Injection automatique des routes

À la fin de la gĂ©nĂ©ration, le systĂšme vous propose d’ajouter automatiquement les routes dans app/Config/Routes.php.

  • Si les routes existent dĂ©jĂ , elles seront ignorĂ©es.
  • Si elles sont absentes, les lignes de route.tpl seront insĂ©rĂ©es aprĂšs confirmation.
  • Une sauvegarde du fichier Routes.php est automatiquement créée avant toute modification.
  • Un rappel manuel est toujours affichĂ© en cas de refus ou de conflit.

Vous pouvez personnaliser les routes injectées en modifiant le fichier route.tpl du thÚme utilisé

🚀 Utilisation

php spark make:crud

Répondez aux questions :

  • Nom de l'entitĂ©
  • Ajout des champs un Ă  un
  • CrĂ©ation des fichiers avec protections

Exemple :

php spark make:crud Produit

📄 Options

Option Description
--force ou -f Forcer l'écrasement des fichiers sans avertissement

🌍 Localisation

Les fichiers de langue sont ici :

app/Language/en/CrudGenerator.php
app/Language/fr/CrudGenerator.php

Vous pouvez les modifier ou en ajouter d'autres.

📁 Structure gĂ©nĂ©rĂ©e

app/
├── Controllers/
│   └── ProduitController.php
├── Entities/
│   └── Produit.php
├── Models/
│   └── ProduitModel.php
├── Views/
│   ├── produit/
│   │   ├── index.php
│   │   ├── create.php
│   │   ├── edit.php
│   │   └── show.php
│   └── templates/
│       ├── header.php
│       └── footer.php
├── Database/
│   └── Migrations/
│       └── 2025-01-01-CreateProduitTable.php

đŸ›Ąïž SĂ©curitĂ©s

  • VĂ©rifie si le CRUD existe dĂ©jĂ 
  • PrĂ©viens si une table est dĂ©jĂ  prĂ©sente dans la BDD
  • Demande avant de remplacer un fichier
  • --force pour tout automatiser

📝 Licence

Licence MIT — Utilisation libre et modification autorisĂ©e.