仅导出 php 中的选定列

Export only selected columns in php

以前是硬编码的,但现在的要求是我只想下载选定的列。

在视图中:

foreach ($allColumnsDBArray as $colHeading) { ?>
    <input type="checkbox" class='form' name="selectedcols[]" value="<?php echo "$colHeading"; ?>" />
    <?php echo $colHeading; echo "<br>";
}

在控制器中:

public function actionExport_csv() {
    $model = new Companies();
    $session = Yii::$app->session;             
    if(isset($_POST['download'])){ if(!empty($_POST['selectedcols'])) {
        foreach($_POST['selectedcols'] as $check) {
            echo $check;//what will be the code here to download column in selectedcols
         }
    } 
}

我使用导出菜单小部件导出选定的列