不正确的导出数据

时间:2017-02-09 06:25:23

标签: yii2

视野中有两个按钮

<div style="width: 50%; margin: 0 auto; text-align: center;">
    <form method="POST">
        <input id="form-token" type="hidden" name="<?=Yii::$app->request->csrfParam?>"
               value="<?=Yii::$app->request->csrfToken?>"/>
        <br><button type="submit" name="last_month" class='btn btn-primary' style="width:120px;height:50px;display:inline-block;" > Прошлый<br> месяц </button>
        <button type="submit" name="pre_last_month" class='btn btn-primary' style="width:120px;height:50px;display:inline-block;margin-top:0;" > Позапрошлый<br> месяц </button>
    </form>
</div>

在控制器中

public function actionIndex()
    {
        $data = null;

//        $data = order::getTest();
        if(isset($_POST['last_month'])) {
            $data = order::getTest();

        }

        if(isset($_POST['pre_last_month'])) {
            $data = order::getCheckPreLastMonth();

        }

        $dataProvider = new ArrayDataProvider([
            'allModels' => $data,
            'sort' => [
            ],
            'pagination' => [
                'pageSize' => 50,
            ],
        ]);

        return $this->render('index',['dataProvider' =>$dataProvider]);
}

当我尝试使用kartik\export\ExportMenu导出数据时,它只导出没有数据的列名称。当我取消注释$data = order::getTest();时,它会正确导出数据,但在单击每个按钮后始终从getTest();导出数据。 UPD。当像这样的行动

    public function actionIndex()
{
    $data = order::getCheck();

    $dataProvider = new ArrayDataProvider([
        'allModels' => $data,
        'sort' => [
            'attributes' => ['order_customFields_delivery_method']
        ],
        'pagination' => [
            'pageSize' => 50,
        ],
    ]);
    return $this->render('index',['dataProvider' =>$dataProvider]);
}

所有数据导出正确 在var_dump($ _ POST)array(2) { ["_csrf-backend"]=> string(56) "MWhMVmJRRkVdWBwJCyl/A2k3IAQlYQwLSVF/GFFpcA12MS8uBT00DA==" ["last_month"]=> string(0) "" }

之后

0 个答案:

没有答案