A lightweight library, that takes care of your routing and file loading
How do you install?
You can use composer
composer require nytrix/cleverload
Or by manually downloading it from here.
Activate Cleverload In order to have cleverload work, you have to
.htaccess from the folder you want Cleverload to handle the request.
RewriteEngine On
RewriteRule ^(.*)$ index.php [NC,L,QSA]
Or when you use a view folder to load your files, you can also use this:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/view/%{REQUEST_URI} -f
RewriteRule (.*) /view/$1 [R=301,L]
RewriteRule ^ index.php [L]
index.php same folder as the .htaccess.
use lib\Cleverload;
use lib\Http\Request;
use lib\Routing\Router;
require_once("autoloader.php");
$request = new Request($_SERVER);
$cleverload = new Cleverload($request);
$cleverload->getRequest()->getRouter()->getResponse();
In the routes folder, you can add files or use the existing web.php file to add routes.
We support GET, POST, PUT, PATCH, DELETE, ALL request, you can route each like so
Route::get("/",function(){});
Route::post("/",function(){});
Route::put("/",function(){});
Route::patch("/",function(){});
Route::delete("/",function(){});
Route::all("/",function(){});
You can also return files instead of functions, your file comes from the viewdir, you can set this in your index.php by adding
$cleverload->viewDir("/path/to/view");
Then you can return a file from there in the routes like so:
Route::get("/","index.php");
In your router, you can also group your request, by for instance prefixes, or namespaces, or domainnames.