HomeDocumentationTutorialsReusability in the Ketroute Framework

Reusability in the Ketroute Framework

Reusability in the Ketroute Framework

In this tutorial, we'll explore the concept of reusability in your Ketroute Framework using the low-code module approach. The Ketroute Framework allows you to efficiently manage components by simply creating configuration files. We'll use a component example called "department" to demonstrate how this works.

Introduction to Reusability

Reusability is a key principle in software development that allows you to use existing code for new functions without rewriting it. This not only saves time but also reduces errors and ensures consistency across your application. In your framework, reusability is achieved by defining configurations for components instead of manually creating forms, validations, audit logging and SQL statements.

Component Example: Department

Let's consider a "department" component with the following modules:

  • List
  • View
  • Add
  • Edit
  • Delete
  • Approve
  • Reject

To enable these modules using the low-code approach, you need to create a configuration file where various parameters and methods are defined.

Configuration File Structure

Table Name

The table name where the department records are saved. This is defined using the tableName method.

PHP
$objConfig->tableName         ('department');

Field Definitions

Define the list of fields and their properties such as name, label, whether they are required, size limitations, and any special validations or formatting.

PHP
$objConfig->text('department_name',    'department-name',          1)->max(100);
$objConfig->telephone('telephone',     'telephone',                0)->max(20);
$objConfig->text('address',            'address',                  0)->max(255);
$objConfig->text('business_unit_name', 'department-business-unit', 1)->max(100);

List Fields

Define the fields from the table that the user will see on the list page using the listFields method.

PHP
$objConfig->listFields(array('department_id','business_unit_name','telephone','address','status_id'));

Sort Fields

Define the fields you want users to see for sorting results.

PHP
$objConfig->sortFields(array('department_name' => KSystemManager::SORT_ASCENDING));

Filter Fields

Define the fields for filtering results using the groupFilterField method.

PHP
$objConfig->groupFilterField('fbdn', $field = 'department_name', 'department-name');
$objConfig->groupFilterField('fbtl', $field = 'telephone', 'telephone');
$objConfig->groupFilterField('fbad', $field = 'address', 'address');

Export Fields

Define the fields that users can export to a PDF or Excel file.

PHP
$objConfig->exportFields(array('department_name','telephone','address','business_unit_name'));

Add/Edit Fields

Define the fields users must complete in forms for adding or editing records using the addFields and editFields methods.

PHP
$objConfig->addFields(array('department_name','telephone','address','business_unit_name'));
$objConfig->editFields(array('department_name','telephone','address','business_unit_name'));

View Fields

Define the fields users will see when viewing the record using the viewFields method.

PHP
$objConfig->viewFields(array('department_name','telephone','address','business_unit_name', 'created_by', 'created_date', 'modified_by', 'modified_date));

Benefits of This Approach

  • Efficiency: By defining configurations, you eliminate the need to create forms, validations, and SQL statements manually.
  • Consistency: Ensures uniformity across different components by adhering to the same structure and rules.
  • Flexibility: Easy to update and maintain. Any changes to the fields or properties can be done in one place.
  • Reduced Errors: Minimizes the risk of human error by automating repetitive tasks.

Conclusion

The low-code module approach the Ketroute Framework significantly simplifies the process of managing components. By creating configuration files, you can quickly define the necessary parameters for your modules, ensuring efficiency, consistency, and flexibility. This method allows you to focus more on the business logic and less on the repetitive tasks of form creation and validation.

Feel free to extend this tutorial with more complex examples and additional configurations to cover other aspects of the Ketroute Framework.