DEV Community

giuliopanda
giuliopanda

Posted on • Originally published at milkadmin.org

Is it time to introduce milkadmin?

I've been working for some time on a simple, lightweight core admin for PHP. It's a basic administrative environment: login, user & permission management, install and updates. I'm finally ready to talk about it.

It's an open-source project I called MilkAdmin.

Installation is "the old way", like WordPress: copy it to the server and you're up and running. You get a minimal environment with access to two databases: one for internal configuration (works well with SQLite) and a second one for your application data.

Development

I'll keep this short and give a few practical examples.

A page in seconds

To create a new page (with a menu entry) you just define a module:

class CupOfMilk extends AbstractModule
{
protected function configure($rule): void
{
$rule->page('cup')
->menu('A cup of milk', '', 'bi bi-cup-hot-fill')
->access('registered');
}
}

Build Calendar Example
The configure method enforces a clear and consistent structure for module rules.

Attributes to keep code readable

I make heavy use of PHP attributes to identify actions and methods:

#[RequestAction('home')]
public function helloWorld() {
Response::render('<h1>Hello World</h1>', []);
}

The models

Models follow a classic approach but use a compact, expressive syntax:

class MyModel extends AbstractModel
{
protected function configure($rule): void
{
$rule->table('#__posts')
->id()
->title()->index()
->text('content')->formType('editor')
->created_at()->hideFromEdit()
->datetime('updated_at')->hideFromEdit()->saveValue(date('Y-m-d H:i:s'));
}
}

Built-in builders

Even though the core is minimalist, I built a set of builders for tables, forms, lists and other UI elements. In the latest version I added a CalendarBuilder:

$calendar = CalendarBuilder::create($this->model, $calendar_id)
->mapFields([
'id' => 'id',
'title' => 'title',
'start_datetime' => 'start_datetime',
'end_datetime' => 'end_datetime',
'class' => function($event, $event_raw) {
return $event_raw->event_class;
}
])
->setMonthYear($month, $year)
->setHeaderTitle('Events Calendar')
->setHeaderIcon('bi-calendar-event')
->onAppointmentClick('?page='.$this->page.'&action=edit&id=%id%')
->onEmptyDateClick('?page='.$this->page.'&action=edit&date=%date%')
->setHeaderColor('primary');

Other features

Very few dependencies.
No external JavaScript libraries. The project includes a small internal system for AJAX responses and theme element handling.
Example: to show a modal from a server response you can return JSON like this:
Response::json([
'status' => 'success',
'modal' => [
'action' => 'show',
'title' => 'Hello World',
'body' => 'Hello World',
]
]);

There's also an integrated permission system and attention to security. For now, I do not recommend using MilkAdmin in production projects without a security review.

The ideal user

I know there are mature, powerful solutions for admin panels. But if you work with WordPress or other PHP platforms, you may not have the time or desire to learn large frameworks, nor to download thousands of files to create a simple table.

MilkAdmin aims to be a lightweight support system, easy to integrate with other systems, and that lets you fall back to plain PHP when needed.

Work in progress

MilkAdmin is not the destination, it's a base for building your ideas. My long-term goal is to develop an advanced reporting system; what's yours?

For a quick experiment, try MilkAdmin on a small personal project: a book list, a link catalog, or a private calendar.

Links

View the repository on GitHub: https://github.com/giuliopanda/milk-admin Visit the project site: https://www.milkadmin.org/

Tip: the Star button is at the top-right corner of the GitHub repository page. If you like the project, please click the star there.

Call to action

If you find MilkAdmin interesting, please give it a try and star the repo. Stars are the first sign of success for an open-source project.

Want help formatting this?

I can also:

  • adapt this as a Medium or blog post;
  • prepare a LinkedIn announcement;
  • turn it into a README or a more technical write-up.

Would you like me to prepare the LinkedIn version as well?

Top comments (0)