I have several views with DynaGrid and ExportMenu. I need every day to save all the exports to an archive as CSV files. I do not know, how to start a new export (which is defined in a DynaGrid) from a controller.
I have found the following possible solutions, but none of them is optimal:
I can define the exports in corresponding models and then realise the exports through actions in controllers, like in this example. But then I have to define the same export twice and I risk, that there will be differences between the two exports.
I can use the Codeception and e.g. in the frame of an acceptance test to simulate a click on the export menu. This solution is relative easy to implement, but I find it unstable.
I can also prepare links to the export files, so it will be easier to make the exports with Codeception. See:
<?= echo yii\helpers\Html::a('Export', ['controller/action'], [ 'class'=>'classname', 'data'=>[ 'method'=>'post', 'params'=>[ 'export_type'=>'CSV', 'exportFull_w0' => '1', 'export_columns' => '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20', 'column_selector_enabled' => '1' ], ] ]) ?>
Is there something more straightforward? I need something like the extension UploadFromUrl, which enables to download files, like this:
$url = 'http://static.yiiframework.com/files/logo/yii.png' ; $path = 'uploads/yii.png'; $file = UploadFromUrl::initWithUrl($url); $file->saveAs($path);
But it does not enable to use post parameters and urls from the current Yii-application.