Ste*_*eve 0 modeladmin silverstripe
我有这门课:
class Product extends DataObject {
static $db = array(
'Name' => 'Varchar',
'ProductType' => 'Varchar',
'Price' => 'Currency'
);
}
Run Code Online (Sandbox Code Playgroud)
数据库表如下所示:
---------------------------------
| Name | ProductType | Price |
|-----------+-------------+-------|
| Product 1 | Type1 | 100 |
| Product 2 | Type1 | 240 |
| Product 3 | Type2 | 10 |
| Product 4 | Type1 | 100 |
---------------------------------
Run Code Online (Sandbox Code Playgroud)
我想有2个模特管理员:
class MyFirstModel extends ModelAdmin {
public static $managed_models = array(
Product
);
}
class MySecondModel extends ModelAdmin {
public static $managed_models = array(
Product
);
}
Run Code Online (Sandbox Code Playgroud)
达到此结果的最佳方法是什么:
MyFirstModel应该告诉我的所有条目,其中ProductType在表Type1和
MySecondModel应该告诉我的所有条目,其中ProductType在表Type2getList()应该是答案.DOC在这里http://doc.silverstripe.org/framework/en/reference/modeladmin#results-customization
所以类似于:
public function getList() {
$list = parent::getList();
if($this->modelClass == 'Product') {
$list->exclude('ProductType', 'Type1');
}
return $list;
}
Run Code Online (Sandbox Code Playgroud)
如果您有2个以上ProductType,则可以使用数组来排除多个值
$list->exclude('ProductType', array('Type2', 'Type3'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
725 次 |
| 最近记录: |