我正在使用Yii2-advanced-app。我正在编写一个函数,它使用post方法&在带有分页的Gridview中显示结果。屏幕是这样的 - 问题 我面临的问题是 - 当我点击分页栏中的“下一页”按钮时,它会再次加载该功能&再次给我空白表格,而不是显示第2页。就像这样 - 。
我的功能就是这个 -
public function actionReportMisc()
{
$model = new BanksDetail();
if($model->load(Yii::$app->request->post())) {
if($model->Process_ID != '' && $model->Bank_ID != '') {
if($model->Process_ID == 1) {
$searchModel = new BanksDetailSearch();
$bank = Banks::find()->select('ID')->where(['Account_Number' => $model->Bank_ID])->one();
if(count($bank) == 1) {
$queryParams = array_merge(array(),Yii::$app->request->getQueryParams());
$queryParams["BanksDetailSearch"]["Bank_ID"] = $bank->ID;
$dataProvider = $searchModel->search($queryParams);
$dataProvider->pagination->pageSize = 3;
if(count($dataProvider) > 0) {
return $this->render('misc', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
} else {
throw new \yii\web\HttpException(404, 'The selected Account does not exist. Please ensure that you have entered right account no. for Bank/Cashbox.');
}
} else if($model->Process_ID == 2) {
$searchModel = new CashboxesDetailSearch();
$cbx = Cashboxes::find()->select('ID')->where(['Account_Code' => $model->Bank_ID])->one();
if(count($cbx) == 1) {
$queryParams = array_merge(array(),Yii::$app->request->getQueryParams());
$queryParams["CashboxesDetailSearch"]["CashBoxes_ID"] = $cbx->ID;
$dataProvider = $searchModel->search($queryParams);
if(count($dataProvider) > 0) {
return $this->render('misc', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
} else {
throw new \yii\web\HttpException(404, 'The selected Account does not exist. Please ensure that you have entered right account no. for Bank/Cashbox.');
}
}
}
} else {
return $this->render('misc', ['model' => $model]);
}
}
据我所知,当我点击“下一页按钮”时,该功能会再次使用空值&返回空的fom。但需要一个建议来完成它或另一种方式来轻松完成它。提前谢谢。
答案 0 :(得分:0)
我解决了问题。使用get()而不是post()的问题。它适用于我的场景,因为我在分页期间每次都会获得这些参数。谢谢你的帮助。