Error in hello world

The last days I played with Slim 4 and tried to find a more “elegant” solution for apache users running a Slim 4 app in a documentRoot public/ or a sub-directory of documentRoot.

Then I discovered $app->setBasePath($basePath). You can pass a fix value or let a function (library) detect the real basePath for you.

Example:

$app = AppFactory::create();

// Set the base path to run the app in a subdirectory.
// This path is used in urlFor().
$basePath = (new BasePathDetector($_SERVER))->getBasePath();
$app->setBasePath($basePath);

Edit: Here you can find the library: selective-php/basepath

1 Like