PHP CRUD Generator is a program developed in pure PHP for building your complete Bootstrap administration panel using a visual UI.
PHPCG is suitable for both non-programmers and advanced PHP programmers, who will have access to a clean and well organized code so they can take advantage of all its potential.
PHPCG is able to analyze your database, extract tables, fields and any type of relationship intelligently.
The analyzed db data can then be used to generate your user administration panel:
Paginated lists (CRUD READ)
record filtering, including with internal/external relational tables
sorting
advanced on-site editing (text, select, Boolean, date and time,...)
nested tables
external data tables (external relations)
export to excel/csv formats
Create & Update forms (CRUD CREATE/UPDATE)
forms built with PHP Form Builder, known for its robustness and reliability
All types of fields
Automatic integration of the best jQuery plugins to improve the user experience (custom select & radio, rich text editor, file uploader, pickers, ...)
drop-down lists with intelligent and customizable content
upload files/images with crop/resize and customizable thumbnail generation
automatic validation according to the type of customizable data
simple and efficient layout - possibility to group the fields into 2 and 3 columns
Delete forms (CRUD DELETE)
Cascading Deleting Dependent Records
Display the number of dependent records that will be deleted
1Upload the required* folders on your server as described in the "package structure" section
2Open the installer - install/index.php - in your browser. If you use a local server + a remote server, you must run the installer on both. More informations available at the Installation/Registration section You'll have to enter your database connection settings for localhost or production server + basic general informations.
3All is now ready to generate your admin panel using the CRUD Generator. Open the generator - generator/generator.php - in your browser.
Installation/Registration
If you use a local server + a remote server, you must run the installer on both.
What does the installer do?
The installer:
Tests your server compatibility (PHP Version, available modules, white rights, ...)
Tests & register your database connection credentials
Checks & registers your license
Creates a MySQL table named "user_data" with your license settings
If you need to reinstall, or have any question/issue with the installation/registration:
Have a look at the video tutorials in the Tutorials
Have a look at the "How To" & "Troubleshooting" sections in the Help Center
Don't change anything here unless you know what you're doing.
USER configuration (General Settings)
This file contains some global settings that can be customized
To change these settings open the Generator in your browser and click the General Settings button.
generator_locked
Allows to lock/unlock the generator access. If the generator is locked, access is protected by an identification page. You will need to enter your email & your purchase code to access it.
admin_locked
Protects the Bootstrap Admin Panel access with a login page if enabled. The Authentication module must be installed. This setting can be changed in the Generator page.
sitename
The main title displayed in the Bootstrap Admin Panel header
admin_logo
The image displayed at the top left of the Bootstrap Admin Panel header. The image file MUST be in the admin/assets/images/ folder.
admin_action_buttons_position
Position of action buttons (update, delete) in the admin READ lists. Can be ' left' or 'right'
auto_enable_filters
Enable filters in the admin lists as soon as a filter is selected in the drop-down list instead of clicking the filter button
lang
The Bootstrap Admin Panel language. The translation file MUST exist in /admin/i18n/
locale_default
Date & time translations for the Bootstrap Admin lists
datetimepickers_style
Date & time pickers style (Default or Material Design)
datetimepickers_lang
Date & time pickers translations for the Bootstrap Admin forms. The language files are located in:
class/phpformbuilder/plugins/pickadate/lib/compressed/translations/ for default style (pickadate plugin)
class/phpformbuilder/plugins/material-datepicker/dist/i18n/ for Material Design style (material-datepicker plugin)
users_password_constraint
Security level of passwords required for creating user access. The different configurations are available here: Passwords available patterns
collapse_inactive_sidebar_categories
Choose if the sidebar of the admin panel behaves like drop-down lists or accordion lists.
Admin Panel Skin (Admin Panel Bootstrap CSS)
Bootstrap CSS classes for the Admin Panel can be customized using the General Settings form
CRUD Generator
Protect access to the Generator with a login page
To protect access to the generator:
Open the Generator in your browser
Click the General Settings button to open the form
Set Lock the Generator to true
Done - when you open generator/generator.php in your browser you'll be redirected to the login page. Enter your registration email & your purchase code to login.
Main Panel
Choose your database in the dropdown list and validate. You will then see the complete panel appear.
Read Lists
Lists filters
Click the "Add Filter" button in the Read Lists generator form to add a new filter.
This will add a new filter to your list.
PHPCG offers you 2 types of filters:
Simple filters
You just have to choose the field to filter in the dropdown list.
Advanced filters
Advanced filters are useful:
if you want to display 2 or more values in the admin dropdown list. For example the first and last name are displayed and the filtered value is the ID.
if you want to filter values from external relationships.
To use advanced filters it is necessary to enter query parameters with joins.
A help button is available to help you build your query, as well as a preview button that allows you to view the generated drop-down list and check its validity.
To build your requests we recommend the excellent software FlySpeed SQL Query
Create/Update Forms
Always build the list view first, and then the forms.
Delete Forms
Always build the list view first, and then the forms.
Admin User Authentification Module
The User Authentification Module installer allows you to configure the rights access to the admin items. It must therefore be installed last, after having created all the elements of the CRUD.
Protected by the users authentication & rights management module
Get records to prefill the form
Create and show the form, including all the plugins (select dropdowns, pickers, uploaders, ...)
PHP Validation
Update the database records or show the errors if wrong values are posted
<?php
use phpformbuilder\Form;
use phpformbuilder\Validator\Validator;
use phpformbuilder\database\Mysql;
use common\Utils;
use secure\Secure;
include_once ADMIN_DIR . 'secure/class/secure/Secure.php';
/* =============================================
validation if posted
============================================= */
if ($_SERVER["REQUEST_METHOD"] == "POST" && Form::testToken('form-edit-actor') === true) {
include_once CLASS_DIR . 'phpformbuilder/Validator/Validator.php';
include_once CLASS_DIR . 'phpformbuilder/Validator/Exception.php';
$validator = new Validator($_POST);
$validator->required()->validate('actor_id');
$validator->integer()->validate('actor_id');
$validator->min(0)->validate('actor_id');
$validator->max(65535)->validate('actor_id');
$validator->required()->validate('first_name');
$validator->maxLength(45)->validate('first_name');
$validator->required()->validate('last_name');
$validator->maxLength(45)->validate('last_name');
$validator->required()->validate('last_update');
$validator->date()->validate('last_update');
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['form-edit-actor'] = $validator->getAllErrors();
} else {
require_once CLASS_DIR . 'phpformbuilder/database/db-connect.php';
require_once CLASS_DIR . 'phpformbuilder/database/Mysql.php';
$db = new Mysql();
$update['first_name'] = Mysql::SQLValue($_POST['first_name'], Mysql::SQLVALUE_TEXT);
$update['last_name'] = Mysql::SQLValue($_POST['last_name'], Mysql::SQLVALUE_TEXT);
$update['last_update'] = Mysql::SQLValue($_POST['last_update'] . ' ' . $_POST['last_update-time'], Mysql::SQLVALUE_DATETIME);
$filter["actor_id"] = Mysql::SQLValue($_POST['actor_id']);
$db->throwExceptions = true;
try {
// begin transaction
$db->transactionBegin();
// update actor
if (DEMO !== true && !$db->updateRows('actor', $update, $filter)) {
$error = $db->error();
$db->transactionRollback();
throw new \Exception($error);
} else {
// ALL OK
$db->transactionEnd();
$_SESSION['msg'] = Utils::alert(UPDATE_SUCCESS_MESSAGE, 'alert-success has-icon');
// reset form values
Form::clear('form-edit-actor');
// redirect to list page
$page_link = '';
if (isset($_SESSION['previous_page_number'])) {
$page_link = '/p' . $_SESSION['previous_page_number'];
}
header('Location:/admin/actor' . $page_link);
// if we don't exit here, $_SESSION['msg'] will be unset
exit();
}
} catch (\Exception $e) {
$msg_content = DB_ERROR;
if (ENVIRONMENT == 'development') {
$msg_content .= '<br>' . $e->getMessage() . '<br>' . $db->getLastSql();
}
$_SESSION['msg'] = Utils::alert($msg_content, 'alert-danger has-icon');
}
} // END else
} // END if POST
$actor_id = $pk;
if (!isset($_SESSION['errors']['form-edit-actor']) || empty($_SESSION['errors']['form-edit-actor'])) { // If no error registered
$qry = "SELECT * FROM `actor`";
$transition = 'WHERE';
// if restricted rights
if (Secure::canUpdateRestricted('actor')) {
$qry .= Secure::getRestrictionQuery('actor');
$transition = 'AND';
}
$qry .= ' ' . $transition . " actor.actor_id = '$actor_id'";
$db = new Mysql();
$db->query($qry);
if ($db->rowCount() < 1) {
if (DEBUG === true) {
exit($db->getLastSql() . ' : No Record Found');
} else {
Secure::logout();
}
}
$row = $db->row();
$_SESSION['form-edit-actor']['actor_id'] = $row->actor_id;
$_SESSION['form-edit-actor']['first_name'] = $row->first_name;
$_SESSION['form-edit-actor']['last_name'] = $row->last_name;
$_SESSION['form-edit-actor']['last_update'] = $row->last_update;
}
$form = new Form('form-edit-actor', 'horizontal', 'novalidate', 'bs4');
$form->setAction('/admin/actor/edit/' . $actor_id);
$form->startFieldset();
$form->setCols(2, 10);
$form->addInput('hidden', 'actor_id', '');
$form->groupInputs('first_name', 'last_name');
$form->setCols(2, 4);
$form->addInput('text', 'first_name', '', 'First Name', 'required');
$form->addInput('text', 'last_name', '', 'Last Name', 'required');
$form->groupInputs('last_update', 'last_update-time');
$form->setCols(2, 10);
$form->addPlugin('pickadate', '#last_update', 'custom-date', array('%format%' => 'dd mmmm yyyy')); // date field
$form->addPlugin('pickadate', '#last_update-time', 'custom-time', array('%interval%' => 15, '%format%' => 'H:i a')); // time field
$form->setCols(2, 6);
$form->addInput('text', 'last_update', '', 'Last Update', 'required');
$form->setCols(0, 4);
$form->addInput('text', 'last_update-time', '', '', 'required, placeholder=Heure');
$form->setCols(2, 10);
$form->addBtn('button', 'cancel', 0, '<i class="' . ICON_BACK . ' position-left"></i>' . CANCEL, 'class=btn btn-warning legitRipple, onclick=history.go(-1)', 'btn-group');
$form->addBtn('submit', 'submit-btn', 1, SUBMIT . '<i class="' . ICON_CHECKMARK . ' position-right"></i>', 'class=btn btn-success legitRipple', 'btn-group');
$form->setCols(0, 12);
$form->centerButtons(true);
$form->printBtnGroup('btn-group');
$form->endFieldset();
$form->addPlugin('nice-check', 'form', 'default', array('%skin%' => 'green'));
Customization for advanced users
If your database structure changes along the way, PHPCG is able to rebuild the data and allows you to regenerate the corresponding CRUD pages.
When generating administration panel pages, PHPCRUD automatically keeps a backup of the previous version.
The file comparison tool integrated with the generator allows you to compare side by side your current version and the previous one, and to merge them by choosing the code blocks to be retained.
Administration customizations can thus be retained during version/structure changes.
Update instructions
Updates are automatic.
When a new version is released, you'll see the "New PHP CRUD GENERATOR version is available" message in /generator/generator.php and will just have to click the "Install" button.
Your version number is available in /conf/conf.php (VERSION)
Special update from version 1.0 (first release)
Copy /generator/update folder to /generator/update on your server.
Open generator/update/first-update.php in your browser. This will install /vendor folder on your server and replace /generator/generator.php with the new version included in
this package.
Open /generator/generator.php in your browser and click the Install button.
The automatic installer will start make the update
Languages/Translation (I18n)
PHP CRUD Generator and the generated Bootstrap admin panel are both fully multi-language.
To translate to your own language:
Duplicate admin/i18n/en.php and rename it to your own language.
Make the translations inside the file that you created (admin/i18n/[your-language].php)
Open conf/user-conf.php and replace define('LANG', 'en'); with the filename you used previously.
Check class/phpformbuilder/plugins/select2/dist/js/i18n/[your-language].js and create it if it doesn't exist.
You're welcome to send us your translation, it'll be useful for other users.
PHP Form Builder
PHP Form Builder is included in the package and you can use it without restriction on the same domain as your CRUD.
This means that you can build any form you want on your website/project and use the integrated plugins & functionalities.
To use PHP Form Builder in your project, include the main conf file on your page add this code at the beginning of your file:
After any update, close & reopen your browser to clear PHP SESSION
version 1.7.7 (04/2020)
Bug Fix:
- fix stupid ROOT path error with subfolder installations due to the previous update
version 1.7.6 (04/2020)
Improvements:
- add a server test file in the install folder to debug paths & urls
- auto-apply ORDER BY changes from the generator to the admin panel without clearing PHP session
- update ElementFilters to allow simple quotes in advanced filters
Bug Fix:
- fix ROOT path with server alias
version 1.7.5 (04/2020)
New Features:
- add an "Ajax loading" option in the generator READ Lists filters (default: false)
Hint: Enable Ajax loading on all the tables that contain a lot of records
This new option allows to load the filters options on demand and will GREATLY improve the loading speed
- add ORDER BY in the generator READ List main settings
- add website search to https://www.phpcrudgenerator.com documentation, tutorials & help center
- add default skin loader for each Bootstrap admin theme CSS in the general settings form
- add the item name in the admin header h1
- add a footer template for admin READ lists (admin/templates/footer.html)
Improvements:
- cleaner generator design
- add instructions to solve 404 errors on some servers (lightspeed) in the help center + admin/.htaccess
- various minor optimizations
Bug Fix:
- fix Tinymce's Responsive file manager url
- edit the cUrl test file in install/
version 1.7.4 (12/2019)
New Features:
- new setting available to choose to show search results in all on the same page or in a paginated list
IMPORTANT: regenerate your READ lists from the generator if you want the paginated search results
or your paginated results will lead to 404 NOT FOUND
Bug Fix:
- fix nested table records in READ lists with only the primary key displayed
- fix the "add new" button link (previously to 404) in READ lists nested tables with page > 1
- the generator delete form now sets the correct stored options for external tables records
version 1.7.3 (12/2019)
New Features:
- add an "Advanced" section in the tutorials with a new "Date and Time formats management logic tutorial
Bug Fix:
- fix wrong date / time formats in admin READ lists for servers without PHP intl extension in some random cases depending on the chosen format
- fix date / time format dropdown helpers in the generator
version 1.7.2 (11/2019)
Improvements:
- add Czech translation
- improve documentation
Bug Fix:
- fix PHP warnings with forms & array values
- fix error in general settings form when no logo is registered
- fix filters query with number values & MySQL 5.7+
- fix error in the Italian translation
- fix PHP warning caused by primary keys aliases in the admin READ lists external relations
version 1.7.1 (08/2019)
Bug Fix:
- Fix the Admin Dropdown Search field cross-browser compatibility
(rebuild your lists to apply)
version 1.7 (08/2019)
New Features:
- New live search with Ajax Autocomplete for Bootstrap Admin Panel READ lists
(rebuild your lists to apply)
Improvements:
- Update Material Pickers for compatibility
version 1.6.1 (07/2019)
New Features:
- Admin filters now can deal with JSON array values (select multiple, checkboxes)
- New PHP CRUD Generator Tutorials channel on Youtube
Improvements:
- Array values from database now displayed as comma-separated values instead of raw JSON
- improve the online Documentation & Tutorials
Bug Fix:
- Rewrite code to limit users rights to their own records
(rebuild your lists / forms to apply)
Improvements:
- The General Settings form in the generator now allows to change the Bootstrap admin main body class
Bug Fix:
- the installer was broken by the previous changes. Solved now.
- Edit in place is no more available in Admin READ lists for users with insufficient rights
- the broken "enable/disable" authentication module in the Generator now works again
version 1.5.5 (06/2019)
New Features:
- The date & Time pickers languages can now be defined in the General Settings form
- You can now choose the style of the Bootstrap admin date & Time pickers
(default | Material Design)
- New Italian translation - Many thanks to Alberto
version 1.5.4 (06/2019)
New Features:
- New General Settings form available in the Generator
- The action buttons of the Bootstrap Admin panel can now be on the left or right of the table
- The filters of the Bootstrap Admin panel can now be triggered automatically when selected
- You can change the site title and admin logo using the General Settings form
- You can change the admin language using the General Settings form
- You can change the admin skin using the General Settings form
Improvements:
- Show custom table names in Admin READ lists nested tables
Bug Fix:
- The Validation button in the Generator should now never overlap the forms
version 1.5.3 (06/2019)
New Features:
- Action buttons in the admin panel can now be displayed in the
1st column of the admin READ lists
Improvements:
- Responsive & others in admin CSS
Bug Fix:
- datepicker plugin
- files & images upload
- tooltips
(these bugs were due to the previous update with latest PHP Form Builder)
New Features:
- replace PHP Form Builder with the latest version 4.2.1
Improvements:
- Admin Panel Fast Loading optimization with the new LoadJS features
- PHP CRUD Fast Loading optimization with the new LoadJS features
- rewrite queries for admin restricted users rights
- upgrade Bootstrap to the latest version 4.3.1
- minor various others improvements
version 1.4.9 (05/2019)
New Features:
- add new Export features (print - current view - all records) in admin READ lists
version 1.4.8 (02/2019)
New Features:
Improvements:
- add (very) strong protection for fileuploader plugin uploads
Bug Fix:
- remove some PHP warnings
- solved admin sidebar duplicate items issue
version 1.4.7 (02/2019)
Bug Fix:
- fix navbar issue with empty icons
version 1.4.6 (02/2019)
New Features:
- New "array" field type in generator for checkboxes & select multiple values
will show JSON decoded values in the READ lists
Improvements:
- better admin navbar content management ("Organize Navbar")
- improve array values management in the generator
Bug Fix:
- fix non-working select multiple with "set" & "enum" field types
- fix changelog url in auto-update success message
version 1.4.5 (02/2019)
New Features:
- License system now accepts domain with multiple extensions
ie: domain.com, domain.eu, domain.co.uk are all valid with the same license.
- New button in the Generator to reload fresh database structure
(When you add or remove tables)
Improvements:
Bug Fix:
- admin filters now accept zero values
- fix queries in admin lists on external tables with direct relation (no intermediate table)
version 1.4.4 (02/2019)
New Features:
- external records from relational tables can now be managed
from the READ LISTS & the CREATE/UPDATE forms (!)
- add self-referential foreign keys management
- tables can now be removed/re-enabled from the admin navbar
- add Spanish admin translation (Thanks to Sergio)
Improvements:
- export buttons (csv/xls[x]) now export the exact filtered list items
- align single fields on the left in admin panels
Bug Fix:
- remove phone validation in auth. module installer
- logout from generator/generator.php now does its job as intended
- upgrade PHPMailer to latest 6.0.6 to fix PHP 7.3 warnings
version 1.4.3 (12/2018)
Bug Fix:
- fix inverted label & value in form CREATE/EDIT templates
- protect relation tables SELECT queries in form CREATE/EDIT templates
version 1.4.2 (10/2018)
New Features:
- new "Add New" button in admin READ lists on external nested tables even if no record
Improvements:
- ADMIN panel: register URL query parameters in $_GET (Altorouter ROUTES doesn't deal with these).
- the ADMIN ADD & UPDATE forms now redirect to the correct list if we come from a nested table (external relation)
- move date_default_timezone_set from conf/conf.php to conf/user-conf.php
- add Help & instructions for Microsoft IIS & NGINX servers
Bug Fix:
- "Add New" button in admin READ lists now always targets the right CREATE form
even if there's several external nested tables in the list.
- Fix several warnings & minor issues
version 1.4.1 (10/2018)
New Features:
- add "Add New", "Edit" & "Delete" buttons in READ Lists nested tables for external tables records
Improvements:
- add compatibility for date & time without PHP intl extension
Bug Fix:
- definitely fix the Apache mod_security error on the install process with some misconfigured servers
version 1.4 (10/2018)
Warning: If you admin READ lists have date or datetime fields, open the corresponding templates in /admin/templates, find the functions toDate(...) and replace the date PHP format with the corresponding ICU date format.
New Features:
- PHPCG includes now the complete latest PHP Form Builder version with all its features & plugins.
- Add the online knowledge base with numerous tutorials & videos
Improvements:
- improve date & time translations management - https://www.phpcrudgenerator.com/tutorials/how-to-translate-dates-times-in-admin-panel
- add full date & time translation in admin lists & forms
- change admin form action from absolute url to root relative url
- add install/curl-test.php to help with CURL debbuging
Bug Fix:
- the generator now retrieves the correct stored values to be displayed in READ lists for the external fields
- get the correct time value in admin edit forms with datetime fields
- solve plugins URL detection with paths containing uppercase letters
version 1.3.2 (08/2018)
Improvements:
- dates edit in place now get the current field value
- image now crop from the center
Bug Fix:
- fix missing fields in update forms due to previous update error
- fix admin lists bug with fields having uppercase characters
- fix admin edit in place with dates & uppercase table name
version 1.3.1 (08/2018)
Improvements:
Bug Fix:
- fix Generator form create profiles
version 1.3 (08/2018)
Notes:
- After this update you may have to reinstall the user authentification module from the Generator page.
Improvements:
- update server-side validation functions to accept empty values,
except for the validators whose internal logic make values required.
Details available here: https://www.phpformbuilder.pro/documentation/class-doc.html#php-validation-methods
- the User Authentification Module now keeps the users & users profiles tables and records when uninstalling.
- the User Authentification Module can now be reinstalled even if the users & users profiles table exist
- improve user profiles management and rights limitations
- the users rights changes now take effect without clearing the session
- the admin sidebar doesn't show empty categories anymore
- the only required fields in users table are now name, firstname, profile ID, email, pass & active
(takes effect on new User Authentification Module installs only)
- add simulate property to Generator.php to simulate when we reset a table structure from generator
- remove several warnings & improve various feedback messages
Bug Fix:
- solve problem with updates & SSL errors on misconfigured servers
version 1.2.4 (07/2018)
Notes:
- After this update you may have to reinstall the user authentification module from the Generator page.
Improvements:
- set default empty value for passwords in UPDATE FORMS
Bug Fix:
- solve CREATE/UPDATE forms generation with custom validation
- solve READ LISTS generation with advanced filders
- solve image path in admin when the field thumbs are not enabled
- remove password validation in UPDATE FORMS if posted value is empty
- correct select values count in generator CREATE/UPDATE forms with custom values
- solve error 500 when adding new users
version 1.2.3 (07/2018)
New Features:
- add an uninstallation process
- add a login module for the generator on the production server
- primary key management in admin forms
Improvements:
- remove the "select database" form in generator & auto select the correct database
- add warnings for non-standard tables & field names (hyphenated)
- improve password fields management in CREATE/UPDATE forms:
better password encryption with Secure class
password are now automatically optional on update forms with an helper text: "Leave blank to keep the current password"
- turn fileuploader debug on for CREATE/UPDATE forms
- improve documentation
- improve auto-validation detection according to forms & database field types
Bug Fix:
- revert Twig template engine to version 1.35.4 to preserve PHP < 7.0 compatibility
- regenerate css & js combined plugin files for CREATE/UPDATE forms when the forms are edited with the generator
- fix generator which failed to validate when custom validators were selected while generating the CREATE/UPDATE forms
- fix password encryption when changes are made in CREATE/UPDATE users table
version 1.2.2 (07/2018)
Improvements:
- add user-conf file to avoid breaking user custom settings with updates
- move the install folder outside the generator folder.
- improve the updater script
- improve url & path management
Bug Fix:
- fix server issues in some special configurations
version 1.2.1 (07/2018)
Warning: if your authentification module is not enabled, after the update open php-crud-generator/conf/admin-lock.php and set ADMIN_LOCKED to false.
Improvements:
- move ADMIN_LOCKED and ADMIN_LOGO to separate files for easier updates
Bug Fix:
- fix several minor bugs