Instead of the include
function, you can use the slim/php-view package, which allows you to render the PHP template directly into the Response object.
Simple example:
Run: composer require slim/php-view
use Slim\Views\PhpRenderer;
// ...
$app->get('/accueil', function (Request $request, Response $response) {
$renderer = new PhpRenderer(__DIR__ . '/../Views');
return $renderer->render($response, 'accueil.php');
});
With Slim it’s preferable to make one route per page?
Yes
Can PHP internal server resolve the problem of the views and index.php? Or do I have to use Apache?
The PHP internal server is just for development purposes. In production, you would use Apache for example. Generally, it works with any type of Webserver that runs PHP. Take a look at my example (see above).
For the Bootstrap menu, I think it needs routes with rendering functionality like buttons instead of URLs. That’s my assumption. Is it wrong?
It depends. Usually the server returns a html page, that loads other resources such as JS and CSS files for Bootstrap and other website features.