mezon/crud-service

小巧的crud-service脚本

1.2.3 2022-06-20 17:10 UTC

This package is auto-updated.

Last update: 2024-09-20 22:28:09 UTC


README

Open Collective Build Status codecov

安装

只需在控制台打印

composer require mezon/crud-service

就这样了)

第一步

现在我们准备创建第一个CRUD服务。看这里

/**
 * Service class
 */
class TodoService extends \Mezon\CrudService\CrudService
{

    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct([
            'fields' => [
                'id' => [
                    'type' => 'integer'
                ],
                'title' => [
                    'type' => 'string'
                ]
            ],
            'table-name' => 'records',
            'entity-name' => 'record'
        ]);
    }
}

$service = new TodoService();
$service->run();

此列表的主要部分是

parent::__construct([
	'fields' => [
		'id' => [
			'type' => 'integer'
		],
		'title' => [
			'type' => 'string'
		]
	],
	'table-name' => 'records',
	'entity-name' => 'record'
]);

在这里,我们描述了我们实体的字段列表、存储的表名和实体名称。

默认端点

开箱即用的CRUD端点列表

GET /list/
GET /all/ 
GET /exact/list/[il:ids]/
GET /exact/[i:id]/
GET /fields/
POST|PUT /delete/[i:id]/
POST|DELETE  /delete/
POST|PUT /create/
POST /update/[i:id]/
GET /new/from/[s:date]/
GET /records/count/
GET /last/[i:count]/
GET /records/count/[s:field]