This repo holds the code for an admin module "Pages" for Bonfire 2, an admin panel for CodeIgniter 4 projects.
The Pages module is a complete example of a Bonfire 2 admin module. It provides Title, Content (with an excerpt for the admin list), URL Slug and Category fields, meta information, and integrates with the parts of the admin that the current Bonfire 2 offers: the sidebar, dashboard widgets, global search, list filters, row and bulk actions, the Recycler, and the permission system.
- CRUD for pages: create, list, search, filter, edit and delete.
- Row and bulk actions in the list. Checking pages opens the floating selection bar with Publish, Unpublish, Move to trash and Delete permanently; each page's row menu offers the same actions.
- Soft deletes with the Recycler. Deleted pages can be restored, and purging a page also removes its meta information.
- Permissions declared by the module itself (
pages.list,pages.create,pages.edit,pages.delete), granted tosuperadminandadminbyphp spark bonfire:permissions. - The "published" state is stored in Bonfire's meta information and shown as a status chip in the list.
- Integration with Bonfire's global search, including meta fields (author name, email and Facebook page).
- Filters by category and creation date, and a search box that works over htmx.
- HugeRTE editor with htmx-powered field validation.
- English and Lithuanian translations.
- PHP 8.2 or newer.
- CodeIgniter 4.7 or newer.
- Bonfire 2 (
develop).
composer require dgvirtual/bonfire2-pages-moduleThe module registers itself with Bonfire from its Config/Registrar: Bonfire finds Module.php, and the permissions
are declared for php spark bonfire:permissions. There is nothing to add to app/Config/Bonfire.php.
-
Copy the directory
Pagesto theapp/Modulesdirectory of your project. -
Uncomment (or add) the module location in
app/Config/Bonfire.php:public $appModules = [ 'App\Modules' => APPPATH . 'Modules', ];
-
Register the module's namespace in
app/Config/Autoload.php, so CodeIgniter reads itsConfig/Registrar.php:public $psr4 = [ APP_NAMESPACE => APPPATH, 'App\Modules\Pages' => APPPATH . 'Modules/Pages', ];
-
Run the module's migration:
php spark migrate -n App\Modules\Pages --all -
Grant the module's permissions to the default groups:
php spark bonfire:permissionsLater changes in Settings → Groups are kept; the command does not give a permission back to a group that an administrator has taken it away from.
-
Copy
Pages/Config/Pages.phptoapp/Configand change the top of the copied file below the PHP tag to:namespace Config; use App\Modules\Pages\Config\Pages as BasePages; class Pages extends BasePages { // class content as is
The config holds the meta fields shown on the page form and the meta fields included in the admin search.
-
Optionally, fill the database with sample pages:
php spark db:seed App\Modules\Pages\Database\Seeds\InsertSamplePages
The Recycler entry for pages is registered by the module itself. You do not need to edit app/Config/Recycler.php.
Open Pages in the admin sidebar. The list can be searched and filtered. Check one or more pages to open the floating bar at the bottom of the list; the same actions are in each row's menu:
| Action | What it does |
|---|---|
| Publish | Marks the page as published through the published meta field. |
| Unpublish | Takes the page down without deleting it. |
| Move to trash | Soft deletes the page; restore it from Tools › Recycler. |
| Delete permanently | Purges the page and its meta information. Cannot be undone. |
Purging asks the admin to type the number of selected pages, since there is no undo.
The module uses the current Admin theme components (<x-page-head>, <x-admin-box>, <x-empty-state>,
<x-status>, <x-row-actions>, <x-selection-bar>, <x-bulk-actions>, <x-save-bar>). If your install published
an older copy of the Admin theme, update the theme files, or the list will not show the floating action bar.
The module ships a feature test that boots Bonfire on CodeIgniter's test application, runs every migration and checks the list, the forms, and every action:
composer install
vendor/bin/phpunitRead the changelog. Recent versions changed the route names (pages-new, pages-create,
pages-edit, pages-save), removed the module's own delete endpoints in favour of Bonfire's actions, and moved the
Recycler and permission setup into the module. Merge any changes in Pages/Config/Pages.php with your
app/Config/Pages.php.
MIT. See LICENSE.