Slim, id, bootstrap and css

Good morning,

English is not my first language, so, please, be patient with my mistakes.
I have trouble with a page “sejour” in my website.

  • I put In the application container DI with the register routes
$app->setBasePath('/slim-secretariat-web');
  • the current folder is: /var/www/html/slim-secretariat-web/public. i verified it with
<?php echo getcwd(); ?>
  • The URL is: http://localhost/slim-secretariat-web/sejours/2

  • the route in the Bootstrap menu is href =“sejours/2”

  • the route in config/routes.php:
    return function (App $app) { ..... $app->get('/sejours/{id}', ControlleurSejours::class . ':requeteSejours'); //récupération des données du séjour };

  • the head.php

<head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Hôpital SoigneMoi</title>
        <!--élimination de l'icone Favicon -->
        <link rel="icon" href="data:,">
        <!--fichiers css bootstrap -->
        <link rel="stylesheet" link href="assets/css/bootstrap.min.css"> <!-- on se positionne par rapporu au dossier public -->
        <!-- fichier personnel --> 
        <link href="assets/css/styles.css" rel="stylesheet"/> <!-- car on lance la commande php -S localhost -public -->
    </head>

With href =“sejours/2” (Vootstrap menu) and /sejours/{id} (routes.php), there is a problem of CSS. With href =“sejour” and /sejours, it’s ok.


Ignore the dates, there is a false date.

Thanks for your help and have good day.

Hello @samclia This topic has been discussed many times in this forum.
Do you use Apache as web server? If so, have you tried this setup?

https://www.slimframework.com/docs/v4/start/web-servers.html#apache-configuration

Hi Odan!
Thanks for your reply.
I use Apache.
I made it:
Run a webstite with the slim apllication
I created the two .htaccess.
Good night.

The <base> HTML element specifies the base URL to use for all relative URLs in a document.

To tell the browser where the basePath is, you can define a “base” tag like this in your layout template:

<head>
    <meta charset="UTF-8">
    <title>Example</title>
    <base href="<?= $basePath ?>/"/>
</head>

Or, if you use Twig:

<base href="{{ base_path() }}/"/>

It doesn’t work. There is no css.

in the container.php, I put $app->setBasePath(‘/slim-secretariat-web’);

App::class => function (ContainerInterface $container) {
       $app = AppFactory::createFromContainer($container);

       // Configuration de le chemin de la base
       $app->setBasePath('/slim-secretariat-web'); //https://www.slimframework.com/docs/v4/start/web-servers.html
       // Register routes
       (require __DIR__ . '/routes.php')($app);

       // Register middleware
       (require __DIR__ . '/middleware.php')($app);

       return $app;
   },

this the head.php:

<head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <base href="<?= $basePath ?>/"> 
        <!--élimination de l'icone Favicon -->
        <link rel="icon" href="data:,">
        <!--fichiers css bootstrap -->
        <link rel="stylesheet" link href="assets/css/bootstrap.min.css"> <!-- on se positionne par rapporu au dossier public -->
        <!-- fichier personnel --> 
        <link href="assets/css/styles.css" rel="stylesheet"/> <!-- car on lance la commande php -S localhost -public -->
    </head>

and in after this instruction in a page :
``

<?php echo getcwd(); ?>
it gives:
/var/www/html/slim-secretariat-web/public

Make sure to pass the basePath variable into your layout template.
Please add more details.

There is no css.

But: <link rel="stylesheet" link href="assets/css/bootstrap.min.css">

Are you sure that there is no CSS? Also the second link is not a valid CSS tag.

Thank you to indicate me the error.
It works with:

<base href="<?= "/slim-secretariat-web" ?>/"/> 

It doesn’t work with:

<base href="<?= $basePath ?>/"/>

I’m thinking I had a dream. The page doesn’t work with the id. I will you give the informations I can give.

I’m sorry to be confused.
I persist:

<base href="<?= "/slim-secretariat-web" ?>/"/> 

works. With

<base href="<?= $basePath ?>/"/>

No CSS work with all the web pages.

Good nigth.

J’ai un très long message sur une page. Le début suffira peut-être.

1 ( ! ) Warning: Undefined variable $basePath in /var/www/html/slim-secretariat-web/src/Views/head.php on line 4 Call Stack #TimeMemoryFunctionLocation 10.0003352128{main}

This is because in this example, $basePath is a template variable that has to be defined and passed from a middleware or controller action.

So I have to define this variable $pathPath and use it:

<base href="<?= $basePath ?>/"/>

It’ related to

$app->setBasePath('/slim-secretariat-web');

So what can I do to use it?

It’s a little complex.

<base href="<?= $basePath ?>/"/>

is ok. Thanks for your help.