Slim Framework Base URL

后端 未结 7 545
太阳男子
太阳男子 2020-12-16 23:34

I\'m new to Slim Framework. How to get the base URL like with the Codeigniter function base_url()?

Thanks

7条回答
  •  误落风尘
    2020-12-17 00:08

    In a recent app where we're using Twig, we assign the httpBasePath as follows:

    $view = $app->view()->getEnvironment();
    $view->addGlobal('httpBasePath', $app->request->getScriptName());
    

    The addGlobal() method is probably equivalent to $app->view()->appendData(), I'm not sure.

    The advantage of using $app->request->getScriptName() is that we don't have to manually set a folder name or care what it is – one developer can have the repo located at http://example.localhost and another can have it at http://localhost/projects/slim and no configuration is required.

提交回复
热议问题