Project Introduction
CRUD - Create, Read, Update, Delete - is the foundation of nearly every data-driven web application. In this chapter you will build a complete CRUD module from scratch, using a simple countries table as your data source. By the end you will have a fully functional admin interface with a paginated list, search, create and edit forms, record detail views, and delete with confirmation.
Want the complete code? The finished countries module is part of the official Trongate c1 repository:
https://github.com/trongate/c1/tree/main/modules/countries
This directory contains the controller, model, all six views, and the navigation link for the admin sidebar.
What We Are Building
The module we are building is a standard Trongate admin CRUD module. It follows the same pattern used by every admin-managed module in the framework: a manage() method for the paginated list, show() for individual records, create() and submit() for adding and editing, and delete_conf() with submit_delete() for removal.
Here is a summary of the methods we will build:
| URL | Method | Purpose |
|---|---|---|
/countries |
index() |
Redirects to /countries/manage |
/countries/manage |
manage() |
Paginated list of all countries, with search and per-page selector |
/countries/show/<id> |
show() |
Detail view of a single country record |
/countries/create |
create() |
Form to add a new country |
/countries/create/<id> |
create() |
Form to edit an existing country (pre-populated) |
/countries/submit |
submit() |
Handle form submission with validation, insert or update the record |
/countries/delete_conf/<id> |
delete_conf() |
Delete confirmation screen |
/countries/submit_delete/<id> |
submit_delete() |
Execute the deletion after confirmation |
/countries/set_per_page/<index> |
set_per_page() |
Change the number of records shown per page |
/countries/search_modal |
search_modal() |
MX-modal for searching records |
/countries/submit_search |
submit_search() |
Process search query and redirect to filtered results |
Prerequisites
Before starting this chapter you should be familiar with:
- The Trongate module structure (controller, model, views)
- The
templates->admin()method for rendering admin pages - Validation rules via
$this->validation->set_rules() - Flashdata for displaying success and error messages
- The
trongate_security->make_sure_allowed()pattern for admin authentication
If you have completed the How To Build A Login System chapter, you already know most of these concepts. This chapter builds directly on that foundation.
We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.
Share your thoughts in the Documentation Feedback.