1. Go to this page and download the library: Download dboho/slim3-rest-controller library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dboho / slim3-rest-controller example snippets
// 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');
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.