dboho / slim3-rest-controller
Simple REST controller for Slim3
v0.7.4
2020-07-22 07:44 UTC
Requires
- php: ~5.6 || ~7.0
- ext-pdo: *
- dboho/simple-database-api: ~0.7
- psr/log: 1.0.0
- slim/slim: ^3.0
Requires (Dev)
- phpunit/phpunit: ^5.0 || ^6.0 || ^7.0
This package is auto-updated.
Last update: 2025-01-07 21:45:28 UTC
README
Dependencies
- dboho/simple-database-api
- slim/slim >= 3.0
- PHP >= 5.5
Usage
// 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'); });
Installation
The recommended installation method is via Composer.
In your project root just run:
$ composer require dboho/slim3-rest-controller