Reputation: 3819
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.
Upvotes: 0
Views: 793
Reputation: 3819
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.
Upvotes: 0