1. Go to this page and download the library: Download baka/router 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 / router example snippets
php
e Baka\Router\RouteGroup;
use Baka\Router\Route;
use Baka\Router\Utils\Http;
$routes = [
Route::add('u')->controller('UsersController')->via(Http::GET, Http::POST),
Route::get('custom-fields'),
Route::put('users')->action('editUser'),
Route::add('companies')->middlewares(
'custom.middleware@before:10,12',
'custom.middleware2@after'
),
];
$anotherRoute = new Route('companies');
$anotherRoute->prefix('/v2')
->controller('CompaniesController')
->namespace('App\\Api\\Controllers')
->via('get','put','post');
$routeGroup = RouteGroup::from($routes)
->addRoute(Route::put('products')->action('edit'))
->addRoute($anotherRoute)
->addMiddlewares('extra.middleware@before')
->defaultNamespace('App\\Default\\Controllers')
->defaultAction('call');
$collections = $routeGroup->toCollections();
var_dump($collections); // 16 Collection instances
// Mount collections to the app
$app = new \Phalcon\Mvc\Micro();
foreach ($collections as $collection){
$app->mount($collection);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.