sitegeist / base-url
确定无前端或后端上下文(如命令或任务)的脚本的基URL
v1.1.7
2024-04-03 06:58 UTC
Requires
- php: >=7.2.0
- typo3/cms-core: ^9.5 || ^10.4 || ^11.5
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-03 07:53:37 UTC
README
在无前端或后端上下文的情况下运行脚本并需要构建URL时,从站点配置中获取绝对URL是一个好主意。此扩展提供了一个辅助类来实现这一点。
使用场景
- 通过cli调用的命令
- 调度任务
功能
- 根据站点配置获取基URL
- 绝对URL或相对URL
入门指南
使用BaseUrl
辅助类的静态函数
\Sitegeist\BaseUrl\Helper\BaseUrl::get(); // https://example.com/
\Sitegeist\BaseUrl\Helper\BaseUrl::prepend('home.html'); // https://example.com/home.html
在您的fluid模板中使用视图辅助函数,例如用于邮件
<baseurl:get /> <!-- https://example.com/ -->
<baseurl:prepend>home.html</baseurl:prepend> <!-- https://example.com/home.html -->
多站点配置设置
如果您的系统有多个站点配置,您可以通过以下方式指定要使用的站点配置:
-
指定站点配置标识符
BaseUrl::get('mysite'); BaseUrl::prepend('home.html', 'mysite');
<baseurl:get identifier="mysite" /> <baseurl:prepend identifier="mysite" />home.html</baseurl:prepend>
-
指定一个页面Uid(在页面树中的任何位置)
BaseUrl::get(null, 1); BaseUrl::prepend('home.html', null, 1);
<baseurl:get pageId="1" /> <baseurl:prepend pageId="1" />home.html</baseurl:prepend>
进一步了解
禁用$asString
返回类型以获取TYPO3\CMS\Core\Http\Uri
对象。现在您可以获取或更改URL的特定部分。
BaseUrl::get(null, null, true, false); BaseUrl::prepend('home.html', null, null, true, false); /* TYPO3\CMS\Core\Http\Uri prototype object scheme => protected "https" (5 chars) supportedSchemes => protected array(2 items) http => 80 (integer) https => 443 (integer) authority => protected "" (0 chars) userInfo => protected "" (0 chars) host => protected "example.com" (11 chars) port => protected NULL path => protected "home.html" (9 chars) query => protected "" (0 chars) fragment => protected NULL */