SilverStripe 可链接模块
SilverStripe Linkable Module
我在扩展数据对象中使用 Link class 作为 $has_one
。但是当我保存我的对象时,Link 值丢失了。
<?php
class Teaser extends DataObject {
private static $db = array (
'Title' => 'Varchar',
'Description' => 'HTMLText'
);
private static $has_one = array (
'Photo' => 'Image',
'MyLink' => 'Link'
);
private static $many_many = array(
'Tags' => 'Tag'
);
private static $summary_fields = array (
// ...
);
public function getCMSFields() {
$fields = FieldList::create(
TextField::create('Title'),
$tags = TagField::create('Tags','Tags',Tag::get(),$this->Tags()),
HTMLEditorField::create('Description', 'Beschreibung'),
LinkField::create('MyLink', 'Weiterleitung', $this->MyLink()),
$uploader = UploadField::create('Photo')
);
// ...
return $fields;
}
}
我在页面中尝试了该示例并且它有效但在 DataObject 中我无法保存该值。
如 Example 中所述,您需要将 ID
添加到字段标题。因为它是一个 $has_one
关系,所以 MyLink
将在数据库中保存为 MyLinkID
。
LinkField::create('MyLinkID', 'Weiterleitung', $this->MyLink())
应该可以解决问题。
我在扩展数据对象中使用 Link class 作为 $has_one
。但是当我保存我的对象时,Link 值丢失了。
<?php
class Teaser extends DataObject {
private static $db = array (
'Title' => 'Varchar',
'Description' => 'HTMLText'
);
private static $has_one = array (
'Photo' => 'Image',
'MyLink' => 'Link'
);
private static $many_many = array(
'Tags' => 'Tag'
);
private static $summary_fields = array (
// ...
);
public function getCMSFields() {
$fields = FieldList::create(
TextField::create('Title'),
$tags = TagField::create('Tags','Tags',Tag::get(),$this->Tags()),
HTMLEditorField::create('Description', 'Beschreibung'),
LinkField::create('MyLink', 'Weiterleitung', $this->MyLink()),
$uploader = UploadField::create('Photo')
);
// ...
return $fields;
}
}
我在页面中尝试了该示例并且它有效但在 DataObject 中我无法保存该值。
如 Example 中所述,您需要将 ID
添加到字段标题。因为它是一个 $has_one
关系,所以 MyLink
将在数据库中保存为 MyLinkID
。
LinkField::create('MyLinkID', 'Weiterleitung', $this->MyLink())
应该可以解决问题。