本文整理汇总了PHP中yii\data\ActiveDataProvider::setKeys方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveDataProvider::setKeys方法的具体用法?PHP ActiveDataProvider::setKeys怎么用?PHP ActiveDataProvider::setKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\data\ActiveDataProvider
的用法示例。
在下文中一共展示了ActiveDataProvider::setKeys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
* @param bool $unimproved
*
* @return ActiveDataProvider
*/
public function search($params = [], $unimproved = false)
{
$query = Release::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params, '');
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'mod_id' => $this->mod_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
$query->andFilterWhere(['<', 'publish_at', $this->publish_at]);
$query->andFilterWhere(['like', 'version', $this->version]);
$query->andFilterWhere(['like', 'file_name', $this->version]);
if ($unimproved) {
$models = $dataProvider->getModels();
$keys = $dataProvider->getKeys();
$unimproved = $this->mod->getUnimprovedReleases($models);
foreach ($unimproved as $release) {
array_unshift($models, $release);
$keys[] = key($models);
}
$dataProvider->setModels($models);
$dataProvider->setKeys($keys);
}
return $dataProvider;
}
示例2: actionIndex
/**
* Lists all Column models.
* @return mixed
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider(['query' => Column::find()->alive(), 'pagination' => ['pageSize' => static::MAX_PAGE_SIZE], 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]);
//递归处理
$dataProvider->models = General::recursiveObj($dataProvider->models, 0, 0, '', '<span class="bank"></span>', false);
$keys = General::getModelsKeys($dataProvider->models, 'id');
$dataProvider->setKeys($keys);
// fb($keys);
// fb($dataProvider->getKeys());
// fb($dataProvider->models);
return $this->render('index', ['dataProvider' => $dataProvider]);
}