Understanding Kotchasan Structure: How to Modify Pages and Related Code
Many developers often ask where to modify a specific page in a program built with Kotchasan. Although I have already explained this in the Router The Heart of the Framework documentation, many developers may not have read it. So, I will summarize it again here.
URL Structure and Related Files
Kotchasan uses a single URL structure to access different pages. The most common URL format is
https://domain.com/index.php?module=<directory>-<page>
When this URL is accessed, the framework will load the file
modules/<directory>/controllers/<page>.php
The render
method or the class \Directory\Page\Controller::render
is executed first. Then, it will call other related classes
-
View (Displays the page content)
- File:
modules/<directory>/views/<page>.php
- Class:
\Directory\Page\View
- File:
-
Model (Handles database and data management for the page)
- File:
modules/<directory>/models/<page>.php
- Class:
\Directory\Page\Model
- File:
When No directory
is Specified
If the URL does not include a directory
, such as
https://domain.com/index.php?module=page
Kotchasan will automatically use the index
directory, meaning the system will call
\Index\Controller\Page
Role of Each Component in MVC
-
Controller (
\Directory\Page\Controller
)- Checks user access permissions
- Prepares page headers such as Title, Breadcrumbs, and Menus
- Passes data to the View
-
View (
\Directory\Page\View
)- Manages the page display, including tables and forms
-
Model (
\Directory\Page\Model
)- Fetches data from the database for the View
- Handles form submissions and table actions
URL Structure for Model Actions
In addition to the standard URL format, another format you might encounter is
index.php/<directory>/model/<page>/action
This calls the action
method in the Model file
modules/<directory>/models/<page>.php
Typically, this type of URL is used for table actions, such as saving, deleting, or updating data.
Conclusion
If you need to modify a page in Kotchasan, analyze the URL structure and edit the relevant Controller, View, or Model according to the MVC pattern.