Silverstripe 4-如何查询从表中获取所有数据并将字段添加到cmsField

问题描述 投票:0回答:1

我想收集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')
    );
php regex database silverstripe
1个回答
0
投票

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'));

© www.soinside.com 2019 - 2024. All rights reserved.