unclecheese/silverstripe-serialised-dbfields 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

unclecheese/silverstripe-serialised-dbfields

Composer 安装命令:

composer require unclecheese/silverstripe-serialised-dbfields

包简介

Provides serialised data (YAML, JSON) in text fields that are traverseable as nested ViewableData objects.

README 文档

README

Provides serialised data (YAML, JSON) in text fields that are traverseable as nested ViewableData objects.

Installation

composer require unclecheese/silverstripe-serialised-dbfields

Recommended add-ons

If you plan on editing the serialised data in the CMS, you'll probably want to install CodeEditorField.

composer require nathancox/codeeditorfield

The database fields are set up to automatically scaffold CodeEditorField when available.

Usage

mysite/code/MyPageType.php

class MyPageType extends Page {
  
  private static $db = [
    'MyJSONData' => 'JSONField',
    'MyYAMLData' => 'YAMLField'
  ];
  
  public function getCMSFields()
  {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.JSONData', CodeEditorField::create('MyJSONData')
      ->setMode('json')
    );
    $fields->addFieldToTab('Root.YAMLData', CodeEditorField::create('MyYAMLData')
      ->setMode('yaml')
    );
    
    return $fields;
  }
}

$MyJSONData

{
  "Category": "Lollies",
  "BannerImage": "/path/to/image.png",
  "Products": [
    {
      "Title": "Snake",
      "Colour": "Red"
    },
    {
      "Title": "Jet plane",
      "Colour": "Purple"
    }
  ]
}

themes/mytheme/templates/Layout/MyPageType.ss

<% with $MyJSONData %>
  Category: $Category<br>
  <img src="$BannerImage"><br>
  <ul>
  $Products.count total products
  <% loop $Products %>
  	<li>$Title ($Colour)</li>
  <% end_loop %>
  </ul>
<% end_with %>

Casting

By default, all scalar values fall back on the $default_cast setting of ViewableData (Text). To customise the casting, use the | symbol in your field value.

Price: Currency|20.00
StartDate: Date|2016-01-01

Tests

framework/sake dev/tests/SerialisedDBFeildsTest

Troubleshooting

Ring Uncle Cheese.

统计信息

  • 总下载量: 6.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-08-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固