在控制器*工作內容*中為您簡單介紹了getList屬性
> 3. 根據子類的getList屬性自動獲取模型對象。
以及getList函數(或方法)
> 5. 已設計好getList()函數(或方法),可提供layui框架的data-table獲取列表參數。并根據子類的getListWith屬性獲取關聯數據
如下面代碼所示,在其中用到model屬性,而model屬性的生成是獲取到了getList屬性的值,而在getList()方法中,使用了
```
Model::all(function(){},$this->getListWith)
```
以上代碼,既說明geListWith是支持字符串與字符串數組的。
### 參考代碼:
```
/**
* 初始化model
*/
private function setModel()
{
$this->model = $this->{'model'.$this->getList};
}
/**
* 獲取列表通用方法
* @return mixed
* @throws \think\exception\DbException
*/
public function getList()
{
$where = [];
$model = 'model'.$this->getList;
foreach (input() as $k => $w ){
if (($k=='page' ||$k=='limit')){
continue;
}
if ($w) $where[$this->model->getTable().'.'.$k] = $w;
}
$qcms = ($this->model)::all(function (Query $query) use ($where){
$query->where($where)->page(input('page')?:1)->limit(input('limit')?:10);
},$this->getListWith ? : null);
$data = LayuiListApiService::getData(($this->$model)->count(),$qcms);
return $data;
}
```