PHP Classes

File: tools/crudgenerator/create-module.php

Recommend this page to a friend!
  Classes of Adrian M   upMVC   tools/crudgenerator/create-module.php   Download  
File: tools/crudgenerator/create-module.php
Role: Example script
Content type: text/plain
Description: Example script
Class: upMVC
Pure PHP web development without other frameworks
Author: By
Last change:
Date: 1 month ago
Size: 1,705 bytes
 

Contents

Class file image Download
<?php
/*
 * Example script to demonstrate usage of CrudModuleGenerator
 */

require_once __DIR__ . '/../../vendor/autoload.php';

use
Tools\CrudGenerator\CrudModuleGenerator;

// Define module name
$moduleName = 'Productbest';

// Define fields with SQL and HTML types including select and radio with options
$fields = [
    [
'name' => 'name', 'sql_type' => 'VARCHAR(100)', 'html_type' => 'text'],
    [
'name' => 'price', 'sql_type' => 'DECIMAL(10,2)', 'html_type' => 'number', 'step' => '0.01', 'min' => '0'],
    [
'name' => 'description', 'sql_type' => 'TEXT', 'html_type' => 'textarea'],
    [
       
'name' => 'category',
       
'sql_type' => 'VARCHAR(50)',
       
'html_type' => 'select',
       
'options' => [
            [
'value' => 'electronics', 'label' => 'Electronics'],
            [
'value' => 'clothing', 'label' => 'Clothing'],
            [
'value' => 'books', 'label' => 'Books'],
            [
'value' => 'food', 'label' => 'Food & Beverages']
        ]
    ],
    [
       
'name' => 'availability',
       
'sql_type' => 'VARCHAR(20)',
       
'html_type' => 'radio',
       
'options' => [
            [
'value' => 'in_stock', 'label' => 'In Stock'],
            [
'value' => 'out_of_stock', 'label' => 'Out of Stock'],
            [
'value' => 'pre_order', 'label' => 'Pre-order']
        ]
    ],
    [
'name' => 'email', 'sql_type' => 'VARCHAR(255)', 'html_type' => 'email'],
];

// Create instance of CrudModuleGenerator
$generator = new CrudModuleGenerator($moduleName, $fields);

// Generate the CRUD module files
$generator->generate();

// Create the database table
$generator->createTable();

echo
"Module '{$moduleName}' created successfully with specified field types.\n";
?>