【问题标题】:How to add title to and avatar in octobercms如何在octobercms中添加标题和头像
【发布时间】:2020-11-26 19:56:51
【问题描述】:

我注意到,如果您单击后端的头像,您可以添加标题和描述,但是当我这样做时,它也不会保存我已经查看了文档,但找不到保存此信息的方法以及如何保存访问此信息,您对上传到后端的文件有相同的行为我想尽可能利用此功能。这就是呼应出来的内容

{
    "id": 23,
    "disk_name": "5f29c6cd94e57384113678.pdf",
    "file_name": "instructions_for_use.pdf",
    "file_size": 388398,
    "content_type": "application/pdf",
    "title": null,
    "description": null,
    "field": "pdf",
    "sort_order": 23,
    "created_at": "2020-08-04 20:36:29",
    "updated_at": "2020-08-04 20:36:32",
    "path": "http://test.test/storage/app/uploads/public/5f2/9c6/cd9/5f29c6cd94e57384113678.pdf",
    "extension": "pdf"
}

描述但找不到存储标题字段的方法

【问题讨论】:

    标签: octobercms octobercms-backend octobercms-widgets


    【解决方案1】:

    为头像添加标题和描述,它的工作原理,

    其文件的标题和描述属性。

    如果你使用attachments $attachOne $attachMany,你也可以使用这个属性。

    https://octobercms.com/docs/database/attachments

    这是普通属性,如果你想设置,你可以很容易地直接设置它们

    例如:


    // if you have relation like this 
    public $attachOne = [
        'avatar' => 'System\Models\File'
    ];
    
    
    // create file instance
    $file = new System\Models\File;
    $file->data = Input::file('file_input');
    $file->is_public = true;
    
    // you can directly set them
    $file->title = 'some title';
    $file->description = 'some description';
    
    $file->save();
    
    // your $model using avatar relation
    $model->avatar = $file;
    $model->save();
    
    // now you can use it directly
    $echo $model->avatar->title; // -> some title
    
    

    查看更多参考资料 文档 https://github.com/octobercms/october/blob/master/modules/system/models/File.php

    Github 表架构system_files https://github.com/octobercms/october/blob/master/modules/system/database/migrations/2013_10_01_000002_Db_System_Files.php

    如有任何疑问,请发表评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-07
      • 2019-01-20
      • 2020-11-20
      • 2018-05-05
      • 2019-02-16
      • 2015-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多