1. Go to this page and download the library: Download baka/http 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/ */
baka / http example snippets
/**
* Need to understand if using this can be a performance disadvantage in the future
*/
$defaultCrudRoutes = [
'business',
'clients',
'contacts',
'modules',
'customFields' => 'custom-fields',
'leads',
'products',
'productType' => 'product-type',
'users',
'sellers',
];
$router = new RouterCollection($application);
foreach ($defaultCrudRoutes as $key => $route) {
//set the controller name
$name = is_int($key) ? $route : $key;
$controllerName = ucfirst($name) . 'Controller';
$router->get('/v1/' . $route, [
'Gewaer\Controllers\\' . $controllerName,
'index',
]);
$router->post('/v1/' . $route, [
'Gewaer\Controllers\\' . $controllerName,
'create',
]);
$router->get('/v1/' . $route . '/{id}', [
'Gewaer\Controllers\\' . $controllerName,
'getById',
]);
$router->put('/v1/' . $route . '/{id}', [
'Gewaer\Controllers\\' . $controllerName,
'edit',
]);
$router->delete('/v1/' . $route . '/{id}', [
'Gewaer\Controllers\\' . $controllerName,
'delete',
]);
/**
* Mounting routes
*/
$router->mount();
}
class AnyController extends Baka\Http\Rest\CrudController
/**
* set objects
*
* @return void
*/
public function onConstruct()
{
$this->model = new Clients();
$this->customModel = new ClientsCustomFields();
}