如何让Silverstripe TableField保存记录
我正在尝试使用 TableField 来管理页面的相关链接列表。我的控件正在工作,除了它没有将 id 保存到数据库(隐藏字段),只是标题和 url
这是使用它的正确方法吗?这么认为。我一直在使用这个: http://doc.silverstripe.org/sapphire/en/参考/tablefield作为一些代码的指导
:
static $has_many = array (
'Linketys' => 'Linkety',
);
$myTableField = new TableField(
'MyTableField', // fieldName
'Linkety', // sourceType
array(
'Title'=>'Title',
'URL'=>'URL'
), // fieldList
array(
'Title'=>'TextField',
'URL'=>'TextField'
), // fieldTypes
null, // filterField (legacy)
"Linkety.PageID",
$this->ID
);
// add some HiddenFields thats saved with each new row
$myTableField->setExtraData(array(
'PageID' => $this->ID ? $this->ID : '$RecordID'
));
$fields->addFieldToTab("Root.Content.Options", $myTableField);
I'm trying to use TableField to manage a list of related links to a page. I have the control working, except it isn't saving the id to the db (a hidden field), just the title and url
Is this the right way to be using it? think so. I've been using this: http://doc.silverstripe.org/sapphire/en/reference/tablefield as a guide
some code:
static $has_many = array (
'Linketys' => 'Linkety',
);
$myTableField = new TableField(
'MyTableField', // fieldName
'Linkety', // sourceType
array(
'Title'=>'Title',
'URL'=>'URL'
), // fieldList
array(
'Title'=>'TextField',
'URL'=>'TextField'
), // fieldTypes
null, // filterField (legacy)
"Linkety.PageID",
$this->ID
);
// add some HiddenFields thats saved with each new row
$myTableField->setExtraData(array(
'PageID' => $this->ID ? $this->ID : '$RecordID'
));
$fields->addFieldToTab("Root.Content.Options", $myTableField);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,文档似乎有点不对劲。
这就是我使用表字段的方式,而不是
使用 extraData Linkety.php
在 Page.php 中
Hmm, the documentation seems to be a bit off.
This is how I use table fields, not using extraData
Linkety.php
In Page.php