【问题标题】:Get full file paths in ProcessWire ServicesPages API在 ProcessWire ServicesPages API 中获取完整的文件路径
【发布时间】:2016-07-15 17:41:23
【问题描述】:

我目前正在使用ProcessWire 构建应用程序。我正在使用ServicePages module 将我的数据公开为类似 REST 的 API。

但是,所有文件似乎都像这样输出:

reel_poster: {
    basename: "breakdown-2015-poster.jpg",
    description: "",
    tags: "",
    formatted: false,
    modified: 1468541707,
    created: 1468541707
}

如何获取所引用文件的实际路径/URL?我需要在 JS 应用中获取路径,所以无法使用 PHP API。

我也发了this on their forums,但那里似乎没有很多活动。

【问题讨论】:

标签: php json rest processwire


【解决方案1】:

所以,如果我阅读this forum post correctly,创建 URL 的唯一方法是手动组装它。我们需要做三件事:

  • 文件资产的基本路径。
  • 该字段所附加到的页面的 ID。
  • 图像名称。

我们知道文件资产的基本路径是/site/assets/files/。假设我们有来自 API 的 page 对象,我们就可以这样做:

var basePath = '/site/assets/files/';
var imagePath = basePath + page.id + '/' + page.image_field.basename;

这应该可以。我认为。 是的。这是经过测试和工作的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 2016-03-31
    相关资源
    最近更新 更多