DEV Community

Cover image for Creating route directory in Slim Php Framework
Asif Sheikh
Asif Sheikh

Posted on

Creating route directory in Slim Php Framework

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);
}
Enter fullscreen mode Exit fullscreen mode

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;
     });
};
Enter fullscreen mode Exit fullscreen mode

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)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more