-
Notifications
You must be signed in to change notification settings - Fork 0
Admin Panel
A lightweight Django-inspired admin: register a model in one file, get a CRUD list/create/edit/delete interface — no per-resource controllers or views to write. Fully isolated inside admin/; depends on tanuki_login (requires an authenticated user with is_admin = 1).
| Piece | File |
|---|---|
| Resource registry |
admin/admin.php — declare which models appear and how |
| Generic controller |
admin/AdminController.php — one controller drives every registered resource |
| Templates |
admin/templates/*.php — independent of the main app's layout |
| Superuser script | admin/create-superuser.php |
1. Add the is_admin column
-- MySQL/MariaDB
ALTER TABLE users ADD COLUMN is_admin TINYINT(1) DEFAULT 0;
-- PostgreSQL
ALTER TABLE users ADD COLUMN is_admin BOOLEAN DEFAULT false;2. Create your first admin account
php admin/create-superuser.phpPrompts for name, email, password; inserts the user with is_admin = 1.
3. Register your models
// admin/admin.php
return [
'todo' => [
'model' => TodoModel::class,
'label' => 'Tasks',
'list_fields' => ['id', 'title', 'completed', 'created_at'],
'form_fields' => [
'title' => ['type' => 'text', 'label' => 'Title'],
'description' => ['type' => 'textarea', 'label' => 'Description'],
'completed' => ['type' => 'checkbox', 'label' => 'Completed'],
],
'order_by' => 'created_at',
'order_dir' => 'DESC',
],
];Field types: text, textarea, checkbox, password. The password type never displays the stored hash and only updates the field when non-empty — required on create, optional (keeps current value) on edit.
4. Enable the routes
// routes.php — top of file
require_once __DIR__ . '/admin/AdminController.php';
// routes array
'GET /admin' => 'AdminController@dashboard',
'GET /admin/{resource}' => 'AdminController@index',
'GET /admin/{resource}/create' => 'AdminController@create',
'POST /admin/{resource}' => 'AdminController@store',
'GET /admin/{resource}/{id}/edit' => 'AdminController@edit',
'PUT /admin/{resource}/{id}' => 'AdminController@update',
'DELETE /admin/{resource}/{id}' => 'AdminController@destroy',admin/templates/layout.php, dashboard.php, index.php, form.php are plain PHP — edit directly. AdminController::render() doesn't use the main app's view(), so admin templates are entirely independent of includes/head.php/footer.php.
- Your own:
/profile(fromtanuki_login) — requires the current password. - Another user's: register
usersinadmin/admin.phpand edit from/admin/users— no current-password check, since it's an admin action on someone else's account.
Delete the admin/ folder, remove the require_once and routes from routes.php. Nothing else in the project references admin/.