Slim Framework Base URL

后端 未结 7 542
太阳男子
太阳男子 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:11

    With Slim v3, as it implements PSR7, you can get a PSR7 Uri object and call the getBasePath() method that Slim3 adds on it. Simply write:

    $basePath = $request->getUri()->getBasePath();
    

    From Slim v3 documentation :

    Base Path

    If your Slim application's front-controller lives in a physical subdirectory beneath your document root directory, you can fetch the HTTP request's physical base path (relative to the document root) with the Uri object's getBasePath() method. This will be an empty string if the Slim application is installed in the document root's top-most directory.

    Be aware that the getBasePath() method is added by the framework and is not part of PSR7 UriInterface.

提交回复
热议问题