shish/microcrud

一个最小化的CRUD生成库

v2.2.2 2024-01-19 17:35 UTC

This package is auto-updated.

Last update: 2024-08-31 13:46:15 UTC


README

一个库,你可以将其指向数据库表,它将为你提供创建/读取/更新/删除操作的一组HTML表单。

我一直在反复地(糟糕地)实现这一系列代码。为了避免第10次糟糕地实现,我决定将其放入一个包含所有功能的自包含库中。

目前这个库使用FFS-PHP的PDO,但如果有任何请求,使用纯PDO也不会太困难。

use \MicroCRUD\{Table, TextColumn, ActionColumn};

class MyTable extends Table {
    public function __construct($db) {
        parent::__construct($db);
        $this->set_columns([
            TextColumn("username", "Username"),
            TextColumn("email", "Email Address"),
            ActionColumn()
        ]);
    }
}

$t = MyTable($db);
print($t->table());
<table>
	<thead>
		[... titles and search fields ...]
	</thead>
	<tbody>
		[... contents of the table, in pages ...]
	</tbody>
	<tfoot>
		[... code to add a new entry ...]
	</tfoot>
</table>

关于任何可能不明显的事物的说明

InetColumn类型支持大多数数据库的精确匹配,但对于Postgres,它支持范围匹配(例如,搜索“1.2.3.0/24”将返回包括“1.2.3.6”在内的搜索结果)。虽然希望跨数据库支持这一功能,但实际操作上,有一个人请求了这个功能,他们使用Postgres作为后端,而Postgres使这变得非常简单 :P