我想收集Devmac_Product
表中的所有数据并作为对象传递,以cms显示
$getCat = "SELECT * FROM Devmac_Product WHERE ProductCategory REGEXP '(32)'";
$objResult = DB::query($getCat);
$f->addFieldToTab(
'Root.Main',
GridField::create(
'Product',
'Product List',
$objResult, // pass $objResult here
GridFieldConfig_RecordEditor::create()
)
->setRightTitle('Editing these products also effects the master list')
);
Silverstripe 4为此提供了最佳解决方案,即
filter及其子类PartialMatch。这里的[[Product是类,而32是任何数字。 Reff:https://docs.silverstripe.org/en/4/developer_guides/model/searchfilters/
用下面的[[statemen t]替换$ objResultProduct::get()->filter(array('ProductCategory:PartialMatch' => '32'));