Skip to content

Create scaffold for LiteRecord#58

Open
henrystivens wants to merge 37 commits intoKumbiaPHP:masterfrom
henrystivens:create-scaffold
Open

Create scaffold for LiteRecord#58
henrystivens wants to merge 37 commits intoKumbiaPHP:masterfrom
henrystivens:create-scaffold

Conversation

@henrystivens
Copy link
Member

No description provided.

henrystivens and others added 30 commits October 5, 2024 12:37
The MySQL schema previously named `ku_admin` has been renamed to `koot`. This includes modifications to the schema and table names, adjusting primary key, unique index, and foreign key constraints to reflect the new schema name.
Updates the admin navigation links to include trailing slashes.
This ensures consistent routing and proper resource loading.
The "Roles" link has been removed.
Improves accessibility by adding aria-label attributes to the navigation elements.
Removes the unused create views for resources and users.
These views are no longer needed and are being removed to clean up the codebase.
Refactors scaffold creation and editing to use ModelLiteForm.

This change introduces a new class `ModelLiteForm` for generating HTML forms based on model metadata.
It simplifies the controller logic and provides a more flexible and maintainable way to create forms.

The changes also ensure that form data persists on validation failure and includes necessary HTML escaping for security.
Removes the dedicated view for creating roles within the admin panel.
This change may be part of a broader refactoring or simplification
of role management functionality.
Ensures correct navigation to the admin users page by adding a trailing slash to the URL in the navigation links.
This resolves an issue where the admin users page was not being loaded correctly.
Ensures email uniqueness during user creation and updates
to prevent duplicate accounts.

Adds checks in `_beforeCreate` and `_beforeUpdate` methods
to validate email existence against the database.
Adds session management to the admin controller. This ensures user sessions are properly handled within the administrative interface.
Sets SQLite as the default database configuration.

This change simplifies initial setup and is more suitable for development environments.
Updates the default SQLite database file name from `ku_admin.db` to `koot.db` for clarity and consistency.
Ensures correct navigation to the admin users page by adding a trailing slash to the URL in the navigation links.
This resolves an issue where the admin users page was not being loaded correctly.
Ensures type safety by explicitly declaring the model property as a string.
Updates the Koot CSS file to reflect the 2025 version.
Improves the data display in tables by ensuring that the "No records" message is displayed correctly when no data is available.
Also, ensures the return statement does not interfere with the rendering of the rest of the page.
Corrects an issue where the conditional `endif` statement was not properly placed, potentially causing rendering errors. This change ensures the conditional logic functions as intended.
Enhances the appearance of the "Record not found" page actions
by applying Bootstrap button styles, improving usability and visual appeal.
Corrects the conditional statement to properly check if the `$data` variable is not set or if it contains no records.
Ensures the "Record not found" message is properly translated
by using the correct PHP syntax for outputting the translated string.
Adds a static `escape` function to handle HTML escaping for user-provided values.
This prevents potential cross-site scripting (XSS) vulnerabilities by ensuring that
all outputted strings are properly sanitized.

Uses the `escape` function to sanitize primary key values, field values, and select options.
Checks if model properties are set before accessing them to avoid undefined property errors.
@henrystivens henrystivens requested a review from joanhey April 18, 2025 23:54
@henrystivens henrystivens requested a review from Copilot August 20, 2025 15:57
@henrystivens henrystivens self-assigned this Aug 20, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR creates a scaffold system for the "LiteRecord" ORM pattern in the Koot framework, transitioning from manual admin views to an automated form generation system. The changes introduce a new form builder class and update existing scaffolding components to use this new approach.

Key changes:

  • Introduces ModelLiteForm class for automatic HTML form generation from LiteRecord models
  • Updates scaffold controller logic to use dynamic model properties and improve error handling
  • Creates new lite scaffold templates that leverage the form builder
  • Updates database configuration and schema from ku_admin to koot

Reviewed Changes

Copilot reviewed 18 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
koot/libs/model_lite_form.php New form builder class that generates HTML forms from LiteRecord model metadata
koot/libs/controller_scaffold_lite.php Updated scaffold controller with improved data handling and error management
koot/views/_shared/scaffolds/lite/create.phtml New create form template using the ModelLiteForm builder
koot/views/_shared/scaffolds/lite/show.phtml Fixed syntax errors and improved localization
koot/views/_shared/scaffolds/lite/page.phtml Fixed logical condition and syntax errors
koot/models/users.php Added validation logic for unique email constraints
koot/config/mysql/koot.sql New database schema replacing the old ku_admin structure
Various admin view files Removed manual form templates in favor of scaffold system

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -0,0 +1,12 @@
<div id="scaffold">
<?php View::content() ?>
<h1><?= ucwords("$model"), ": <span>$action_name</span>" ?></h1>
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comma operator is incorrectly used in the echo statement. It should use concatenation (.) instead of comma to properly combine the strings.

Suggested change
<h1><?= ucwords("$model"), ": <span>$action_name</span>" ?></h1>
<h1><?= ucwords("$model") . ": <span>$action_name</span>" ?></h1>

Copilot uses AI. Check for mistakes.
// Success message and return to the list
Flash::valid(_('Record created'));
Redirect::toAction('');
return;
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is inverted. The condition should check if creation succeeds (without the '!' operator) to show success message and redirect.

Suggested change
return;
if ($obj->create(Input::post($this->model))) {
// Success message and return to the list
Flash::valid(_('Record created'));
Redirect::toAction('');
return;
} else {
Flash::error(_('Something was wrong'));
// If it fails the data is persistent in the form
$this->{$this->model} = $obj;
return;
}

Copilot uses AI. Check for mistakes.
// Success message and return to the list
Flash::valid(_('Record updated'));
Redirect::toAction('');
if (!$this->{$this->model}->update(Input::post($this->model))) {
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is inverted. The condition should check if update succeeds (without the '!' operator) to show success message and redirect.

Copilot uses AI. Check for mistakes.

// If the field ends with '_id', use a database select
if (str_ends_with($field, '_id')) {
$fieldValue = $model->$field ?? '';
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable $fieldValue is assigned but never used. Consider removing it or using it in the Form::dbSelect call instead of the separate call on line 165.

Copilot uses AI. Check for mistakes.
// If the field ends with '_id', use a database select
if (str_ends_with($field, '_id')) {
$fieldValue = $model->$field ?? '';
$html .= Form::dbSelect("{$modelName}.{$field}", null, null, 'Select', '', $fieldValue) . PHP_EOL;
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable $fieldValue is used but it was defined in the previous line. However, it should use $model->$field ?? '' directly or ensure the variable is properly utilized.

Suggested change
$html .= Form::dbSelect("{$modelName}.{$field}", null, null, 'Select', '', $fieldValue) . PHP_EOL;
$html .= Form::dbSelect("{$modelName}.{$field}", null, null, 'Select', '', $model->$field ?? '') . PHP_EOL;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants