HomeDocumentationTutorialsFile Structure of a Component

File Structure of a Component

Welcome to the tutorial on the file structure of a component in Ketroute Framework. This tutorial will guide you through the various files and directories that make up a typical component, explaining their purposes and how they fit together. By the end, you'll have a clear understanding of how to organize and manage your components effectively. Teh tutorila will also share an insight on configuring your component.

Overview

In Ketroute Framework, a component is a self-contained unit that encapsulates a specific piece of functionality(modules) or a UI element(templates). Components utilize the reused capabilities of the Ketroute Framework to build complex applications. Understanding the file structure of a component is crucial for maintaining a clean and scalable codebase.

Directory Structure

A typical component in Ketroute Framework  will have a well-defined directory structure. This section outlines the standard layout and the rationale behind it.

INFO
|  component-name
|   ---- application
|    ------ ---- intranet
|    ------------ ---- css
|    --------------------- ---- style.css
|    ------------ ---- js
|    --------------------- ---- script.js
|    ------------ ---- modules
|    --------------------- ---- list.php
|    --------------------- ---- add.php
|    --------------------- ---- edit.php
|    --------------------- ---- delete.php
|    ------------ ---- templates
|    --------------------- ---- list.tpl
|    --------------------- ---- add.tpl
|    --------------------- ---- edit.tpl
|    --------------------- ---- delete.tpl
|    ------------ ---- confugurations.php  
|   ---- classes 
|    ------ ---- EmployeeManager.php 
|   ---- cronjobs  
|    ------ ---- cron
|    ------------ ---- modules
|    --------------------- ---- birthday-notification.php
|   ---- images  
|    ------ ---- employee-list.svg
|    ------ ---- employee-add.svg 
|   ---- languages  
|    ------ ---- en.xml
|   ---- routine-helper  
|    ------ ---- process-name1.php
|    ------ ---- process-name2.php
|   ---- webservices 
|    ------ ---- EmployeeService.getProfile.php
|    ------ ---- EmployeeService.updateProfile.php

 

Key Files and thier Purpose

Component Configuration

The component configuration file plays a big role in making sure that all fields, tables and rules are property defined as per the requirements. Understanding the configuration file helps in making sure developers don't find themselves writing processes and functionality that already exists within the framework, only because of lack of knowhow.

 

Here is an example of a employee component that lets you capture simple details of an employee, and Ketroute Framework will handle the rest:

  • list results
  • results search and filters
  • form rendering
  • form validation
  • export results to PDF & Excel/CSV
  • Form to Add, edit, Delete Record
PHP
$objConfig = new KConfiguration();
$objConfig->tableName         ('employee');
 
$objConfig->listFields        (array('firstname','surname','birthdate','email','mobile','job_title', 'status_id'));
$objConfig->addFields         (array('firstname','surname','birthdate','email','mobile','job_title'));
$objConfig->editFields        (array('firstname','surname','birthdate','email','mobile','job_title'));
$objConfig->viewFields        (array('firstname','surname','birthdate','email','mobile','job_title'));
$objConfig->exportFields      (array('firstname','surname','birthdate','email','mobile','job_title'));
 
$objConfig->searchFields      (array('firstname'));
$objConfig->sortFields        (array('firstname'           => KSystemManager::SORT_ASCENDING, 'surname'           => KSystemManager::SORT_ASCENDING));
$objConfig->primaryKey        ('id');
$objConfig->titleField        ('firstname');
$objConfig->a2zField          ('firstname');
 
$objConfig->text('firstname',    'empployee-firstname',     1)->max(100);
$objConfig->text('surname',      'empployee-surname',       1)->max(100);
$objConfig->email('email',       'empployee-email',       1);
$objConfig->i18nMobile('mobile', 'empployee-mobile',        1);
$objConfig->text('job_title',    'empployee-job-title',     1)->max(100);
$objConfig->date('birthdate',    'empployee-birthdate',     1)->noFutureDate(true);
 
return $objConfig->getConfiguration();

 

Understanding and organizing the file structure of a component is crucial for developing maintainable and scalable applications in Ketroute Framework. By following the standard structure and best practices outlined in this tutorial, you'll be well-equipped to create robust components that integrate seamlessly into your projects.

Thank you for following along with this tutorial. Happy coding!