简体   繁体   中英

Yii2 : Managing Pagination in custom function

I'm using Yii2-advanced-app. I'm writing a function which takes 2 parameters using post method & displays result in a Gridview with pagination. The screen is like this - 屏幕参考 The problem I'm facing with this is - When I click on the 'next page' button in pagination bar, it loads the function again & gives me the blank form again, instead of showing the 2nd page. It's like this - 没有结果的空表格 .

My function is this -

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]);
        }
    }

I understand that, when I click on 'next page button', the function again initializes the form with empty values & returns empty fom. But need a suggestion to get it done or an another way to do it easily. Thanks in advance.

I solved the resp. problem by using get() instead of post(). It was suitable for my scenario, because I get those parameters each time during pagination too. Thanks for your kind help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM