【问题标题】:How can I get the url of featured image from Rainlab blog plugin?如何从 Rainlab 博客插件中获取特色图片的 url?
【发布时间】:2018-04-11 05:48:04
【问题描述】:

我需要知道 10 月 CMS 中带有 Rainlab 博客插件的博客文章中附加的特色图片的网址。

图像保存在类似“.../storage/app/uploads/public/59f/112”的目录中

我需要在保存帖子的那一刻知道它,因为我想获取 url 以将其保存在另一个表中,它可以从另一个 php 文件或系统(例如在 Android 应用程序中)访问,但我可以不要这样做。

我尝试(在 FormController.php 中)找到帖子:

$modelP = Post::find($this->controller->vars['formModel']['id']);
$featuredImage = $modelP->featured_image->getPath();

但不起作用,我得到了 blog 对象,但它说 features_image 不是变量。

仅在表 system_file 中,我可以获取文件的名称(disk_name),但不能获取整个 url,而且我不知道它保存在哪个目录中。

谁能帮帮我?

【问题讨论】:

  • 你把这段代码放在什么地方了?
  • 在 FormController.php -> create_onSave()

标签: php octobercms octobercms-plugins october-form-controller


【解决方案1】:

不是单数,而是复数

$featuredImage = $modelP->featured_images()->first();

编辑:首先使用

【讨论】:

  • 谢谢。 Yes 是复数,但使用 get() 返回 October\Rain\Database\Collection 对象。我需要gePath()。
【解决方案2】:

如果您使用的是雨实验室插件,那么我们确实有一些解决方案

首先它的featured_images不是featured_image

它会返回一组图像,所以如果你需要它的第一张图像,那么你可以替换像

这样的代码
$modelP = Post::find($this->controller->vars['formModel']['id']);
$featuredImage = $modelP->featured_images->first()->getPath();

$featuredImage这是图片的完整路径

任何其他困惑请评论,快乐编码:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-24
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    • 2018-06-17
    相关资源
    最近更新 更多