HomeDocumentationTutorialsWorking with Reuse Module and Automated Fields

Working with Reuse Module and Automated Fields

Overview

The reuseModule() function in your framework provides an efficient way to reuse pre-defined configurations for modules without the need to manually redefine them. However, when dealing with automated fields, it is important to control whether they should be included in the process.

 

Handling Automated Fields

Automated fields are fields that the framework automatically assigns values to when performing actions like adding, editing, deleting, approving, or rejecting a module.

If automated fields have been set prior to calling $objConfig->reuseModule(), you must explicitly send a false flag ($include_automated_fields = false) to prevent the framework from overriding them with its default values.

 

Consequences of Not Sending false Flag

If you do not send false when calling $objConfig->reuseModule(), the framework will automatically assign default values to control fields, which might not be the intended behavior. Below are the default behaviors:

 

1. Adding a Module

  • status_id will be set to ACTIVE.
  • created_by will be set if the user is logged in.
  • created_date will be set to the current timestamp.

2. Editing/Deleting/Approving/Rejecting a Module

  • modified_by will be set if the user is logged in.
  • modified_date will be set to the current timestamp.

 

Implementation Example

Using reuseModule() Without Automated Fields

If automated fields have been set beforehand, explicitly pass false when calling $objConfig->reuseModule():

PHP
$objConfig->reuseModule($module_name, false);

This ensures that the framework does not override existing automated fields.

Using reuseModule() With Default Automated Fields

If you want the framework to handle automated fields using its default values, simply call:

PHP
$objConfig->reuseModule($module_name);

By default, $include_automated_fields is true, meaning the framework will assign values as per its default rules.

 

Best Practices

Always check if automated fields have been set manually before calling reuseModule().

Use false for $include_automated_fields when you need to retain custom-set values.

Ensure proper user authentication so that created_by and modified_by fields capture the correct user.

Log all automated field updates for better auditing and debugging.

 

Conclusion

Managing automated fields properly when using reuseModule() is crucial to prevent unintended data overwrites. By correctly setting the $include_automated_fields flag, you can ensure that your module operates with the expected data values, maintaining accuracy and consistency across your system.