【问题标题】:Fetching the file path attached to a model through a parent model relation?通过父模型关系获取附加到模型的文件路径?
【发布时间】:2017-07-08 01:38:35
【问题描述】:

我有一个名为 application 的模型,它可以获取另一个名为 resume 的模型的关系。在简历模型中是进一步的关系,它具有文件的 $attachOne 关系。

public $attachOne = [
    'resume' => ['System\Models\File','public' => false, 'delete' => true]
    ];

该应用程序通过 $belongsTo 附加了一份简历。

public $belongsTo = [
    'user' => ['RainLab\User\Models\User', 'table' => 'users'],
    'resume' => ['Acme\Job\Models\Resume']
    ];

我可以获取应用程序模型中的所有字段以进行简历,例如 user_id、display_name 等,但是当我尝试访问附加到简历的文件时,它显示未找到列。这是我在访问简历数据的应用程序模型中的内容。

resume:
    label: Resume File
    type: relation
    disabled: true
    select: display_name

我可以选择该表中的所有字段,但无法访问附加到简历表的文件。有什么方法可以访问应用程序模型中附加的系统文件?

【问题讨论】:

  • 您是如何访问该字段的?
  • 在 fields.yaml 我想在后端访问它
  • 您想查看表单上呈现的值或文档路径,还是要修改其中的文件?
  • 只看下载文件的文件路径。文件没有变化。

标签: php laravel eloquent octobercms


【解决方案1】:

您可以使用 partial 来访问您的相关模型附件,如下所示。

第 1 步。

设置你的 fields.yaml

resume:
  label: Resume File
  type: partial
  path: $/acme/jobs/models/resume/_resume.htm
  1. 在简历的模型目录中创建一个部分,以打印出文件的下载链接

  2. 在部分内部,您可以访问 $model 变量,该变量保存模型的当前实例(如果存在),例如:

/acme/jobs/models/resume/_resume.htm

<?php if ($model->resume->resume): ?>
 <div class="form-group  text-field span-full form-pad" data-field- name="resume" id="Form-field-resume-group">
    <div>
        <a href="<?= $model->resume->resume->getPath(); ?>">Download   resume</a>
    </div>
</div>
<?php endif; ?>

【讨论】:

  • 感谢您的回复。我不确定 10 月能否做到这一点!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-04
  • 2019-10-24
相关资源
最近更新 更多