Hello Everyone,
I have discussed on creating route directory in slim php framework. It makes easy to organize or modular your slim project.
Let's go,
STEP 1:
Firstly, copy your code in public/index.php
:
$routes = glob(__DIR__ . "/../routes/*.php");
foreach($routes as $route)
{
(require $route)($app);
}
STEP 2:
In second step, we'll create routes directory in our slim project directory and also create routes/web.php
file:
Like this,
<?php
use Slim\App;
return function (App $app)
{
$app->get("/your-route", function ($request, $response, $args){
$response->getBody()->write("Hello, I am in your route");
return $respones;
});
};
I hope you to enjoy for creating such routes separate files that may be slim code organizable, readable.
Thank you for giving your valuable time to read this!✨
Top comments (0)