This repo holds the code for an admin module "Pages" for Bonfire 2, an admin panel for CodeIgniter 4 projects.
Pages module is a very basic implementation of a module of Bonfire 2 admin panel for administration of pages on a website.
Bonfire 2 includes instructions how to make an admin module, but there is no complete example. I followed the instructions and looked at examples in Bonfire 2 code itself to implement this admin module, for learning purposes mostly. But my work might be useful for you as well.
- CRUD (Create, Read, Update, Delete) functionality for pages, that have Title, Content (and Excerpt for display in admin interface mainly), Slug and Categories fields;
- integration with Bonfire 2 admin interface and functionality (Menu, Widgets, Search, Filter, Recycler);
- full localization (though don't expect too much, Bonfire 2 itself is not yet properly localized);
- HTMX-powered field validation on the frontend (not available elsewhere in Bonfire 2!);
You should have a Codeigniter 4 installation with Bonfire 2 installed (refer to Bonfire 2 docs to learn how to do that).
-
Check that your
app/Config/Bonfire.phpfile includes this location of the Modules (you will have to uncomment the'App\Modules' => APPPATH . 'Modules'line):public $appModules = [ 'App\Modules' => APPPATH . 'Modules', ];
-
Copy the directory
Pagestoapp/Modulesdirectory of your project (or another directory, if the $appModules points to another one in your installation). -
Open the
app/Config/AuthGroups.phpfile and add the following permissions to the $permissions array:public array $permissions = [ // Original permissions here... // ... // Pages module related permissions: 'pages.list' => 'Can view list of pages', 'pages.view' => 'Can view pages details', 'pages.create' => 'Can create new pages', 'pages.edit' => 'Can edit existing pages', 'pages.delete' => 'Can delete existing pages', 'pages.settings' => 'Can manage pages settings in admin area', ];
-
Also review the
array $matrixin the same file and add thepages.*permissions tosuperadminandadmingroups and the other groups that should have permissions to access the Pages module in the admin panel.
Note that any changes you make in an existing installation, where you have done changes to permissions on live website via admin interface, will require you to delete the corresponding entries from admin interface and configure them anew, since the permissions from config in Bonfire are only picked one time, and then they are managed from database exclusively.
-
Configure recycler. Edit
app/Config/Recycler.phpproperty$resourcesby addingpagesto it, so it looks something like:public $resources = [ // Original users array here... ], 'pages' => [ 'label' => 'Pages', 'model' => 'App\Modules\Pages\Models\PagesModel', 'columns' => [ 'id', 'title', 'excerpt', 'deleted_at', ], ], ];
-
Copy Pages/Config/Pages.php file to
app/Config.
In the copied file change the top part of the file below php tag to:
namespace Config;
use App\Modules\Pages\Config\Pages as BasePages;
class Pages extends BasePages
{
// class content as is-
To update the database, run this command from the base directory of your Codeigniter install:
php spark migrate -n App\\Modules\\Pages --all
And, if you wish (it is not necessary), you can populate the database with some randomly generated pages:
`php spark db:seed App\\Modules\\Pages\\Database\\Seeds\\InsertSamplePages`
(on Windows replace double slashes with single).
That should be it.
When updating, repeat step 2, read the changelog to see what's new,
and check if there are any significant changes in the config file Pages.php
to be merged with the file in your app/Config/Pages.php.