dboho/slim3-rest-controller

Slim3 的简单 REST 控制器

v0.7.4 2020-07-22 07:44 UTC

This package is auto-updated.

Last update: 2024-09-07 20:52:43 UTC


README

Travis branch Codecov Software License

依赖

使用

// dependencies container
$container = $app->getContainer();

$container[TableController::class] = function ($c) {
    $pdo = new PDO('sqlite:database.db');
    $dataAccess = new DataAccess($pdo);
    return new TableController($dataAccess);
};

// routes for tables books, videos and images
$app->group('/api/{table:books|videos|images}', function () {

    // get all entries in books or a subset selected with query-parameters
    $this->get('', TableController::class . ':getAll');
    
    // get one entry
    $this->get('/{id:[0-9]+}', TableController::class . ':get');
    
    // add one entry
    $this->post('', TableController::class . ':add');
    
    // update one entry
    $this->put('/{id:[0-9]+}', TableController::class . ':update');
    
    // update all entries or a subset selected with query-parameters
    $this->put('', TableController::class . ':update');
    
    // delete a specific entry
    $this->delete('/{id:[0-9]+}', TableController::class . ':delete');
    
    // delete all entries or a subset selected with query-parameters
    $this->delete('', TableController::class . ':delete');
});

安装

推荐安装方式是通过 Composer

在项目根目录下运行

$ composer require dboho/slim3-rest-controller