不同的形式动作Pjax YII2

时间:2016-09-20 21:27:48

标签: javascript jquery yii2 pjax

如何在Pjax中进行两种不同的表单操作? 我的表格:

<?php
Pjax::begin();

echo Html::beginForm(['/'], 'POST', ['data-pjax' => '', 'class' => 'form-inline', 'id'=>'set_filters', 'name'=>'set_filers']);

foreach ($aFilters as $aData) {
    echo Html::radioList($aData['question']->id, $aFiltersData ,ArrayHelper::map($aData['answer'], 'id', 'name'), ['class'=>'answer']);
}
?>

<?= Html::SubmitButton('Pokaż projekty', ['class' =>'project_ready', 'name' =>'project_ready'])?>
<?= Html::endForm() ?>

<?= $sProjectCount ?>

<?php Pjax::end(); ?>

$sProjectCount正确更改。但我需要一些按钮,使用此表单中的POST数据重定向到第二页。

来自控制器的

$sProjectCount

public function actionIndex()
{
    $model = new ProductsSearch();

    $oFiltersGroup = new FiltersGroup();
    $oFilters      = new Filters();
    $aFiltersData  = [];

    $query = $model::find();
    $query->joinWith(['productsFilters']);

    $dataProvider = new ActiveDataProvider([
        'query'      => $query,
        'pagination' => false,
        'sort' => [
            'defaultOrder' => [
                'id' => SORT_ASC,
            ]
        ]
    ]);

    if (Yii::$app->request->post() && count(Yii::$app->request->post()) >= 2 ) {
        foreach (Yii::$app->request->post() as $Filters) {
            if (is_numeric($Filters)) {
                $aFiltersData[] .= $Filters;
            }
        }

        $query
            ->andFilterWhere(['IN', 'products_filters.filters_id', $aFiltersData])
            ->groupBy('id')
            ->having('COUNT(*)='.count($aFiltersData));
    }
    $sProjectCount = $dataProvider->count;
    $aFiltersGroup = $oFiltersGroup::find()
        ->where(['is_active'=> 1])
        ->orderBy('sort_order')
        ->all();

    foreach ($aFiltersGroup as $_aFiltersGroup){

        $aFilters = $oFilters::find()
            ->where(['filters_group_id' => $_aFiltersGroup->id, 'is_active' => 1])
            ->all();

        $aData[$_aFiltersGroup->id] = ['question'=>$_aFiltersGroup, 'answer' => $aFilters];
    }

    return $this->render('index', [
        'model'         => $model,
        'sProjectCount' => $sProjectCount, 
        'aFilters'      => $aData, 
        'aFiltersData'  => $aFiltersData
    ]);
}

也许相同的JS或jQuery可以提供帮助。

0 个答案:

没有答案