Silverstripe ModelAdmin数据对象
我有这门课:Silverstripe ModelAdmin数据对象,silverstripe,modeladmin,Silverstripe,Modeladmin,我有这门课: class Product extends DataObject { static $db = array( 'Name' => 'Varchar', 'ProductType' => 'Varchar', 'Price' => 'Currency' ); } 数据库表如下所示: --------------------------------- | Name | Produ
class Product extends DataObject {
static $db = array(
'Name' => 'Varchar',
'ProductType' => 'Varchar',
'Price' => 'Currency'
);
}
数据库表如下所示:
---------------------------------
| Name | ProductType | Price |
|-----------+-------------+-------|
| Product 1 | Type1 | 100 |
| Product 2 | Type1 | 240 |
| Product 3 | Type2 | 10 |
| Product 4 | Type1 | 100 |
---------------------------------
我想要两个模型管理员:
class MyFirstModel extends ModelAdmin {
public static $managed_models = array(
Product
);
}
class MySecondModel extends ModelAdmin {
public static $managed_models = array(
Product
);
}
达到这一结果的最佳方法是什么:
应显示表中MyFirstModel
为ProductType
Type1
应显示表中MySecondModel
为ProductType
Type2
getList()
应该是答案。这里是医生
比如:
public function getList() {
$list = parent::getList();
if($this->modelClass == 'Product') {
$list->exclude('ProductType', 'Type1');
}
return $list;
}
如果有2个以上的ProductType
,则可以使用数组排除多个值,如
$list->exclude('ProductType', array('Type2', 'Type3'));
getList()
应该是答案。这里是医生
比如:
public function getList() {
$list = parent::getList();
if($this->modelClass == 'Product') {
$list->exclude('ProductType', 'Type1');
}
return $list;
}
如果有2个以上的ProductType
,则可以使用数组排除多个值,如
$list->exclude('ProductType', array('Type2', 'Type3'));
非常感谢。添加新产品时:如何确保在FirstModel中添加新产品时,将值类型1保存在ProductType行中,在SecondModel中添加产品时,将值类型2保存?这将有点复杂,而且不会直接显示出来。您可能希望查看
ModelAdmin
上的重载getEditForm()
,并查看GridField上的组件,可能是GridFieldAddNewButton
。或者可以检查数据对象的getCMSFields()
中的URL/referer。这里没有承诺,你得四处看看……谢谢!添加新产品时:如何确保在FirstModel中添加新产品时,将值类型1保存在ProductType行中,在SecondModel中添加产品时,将值类型2保存?这将有点复杂,而且不会直接显示出来。您可能希望查看ModelAdmin
上的重载getEditForm()
,并查看GridField上的组件,可能是GridFieldAddNewButton
。或者可以检查数据对象的getCMSFields()
中的URL/referer。这里没有承诺,你得四处看看。。。