Skip to content

Commit

Permalink
Update ExportController post data method
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Dec 5, 2015
1 parent d6a94f9 commit db02213
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class ExportController extends Controller
*/
public function actionDownload()
{
$type = empty($_POST['export_filetype']) ? 'html' : $_POST['export_filetype'];
$name = empty($_POST['export_filename']) ? Yii::t('kvgrid', 'export') : $_POST['export_filename'];
$content = empty($_POST['export_content']) ? Yii::t('kvgrid', 'No data found') : $_POST['export_content'];
$mime = empty($_POST['export_mime']) ? 'text/plain' : $_POST['export_mime'];
$encoding = empty($_POST['export_encoding']) ? 'utf-8' : $_POST['export_encoding'];
$config = empty($_POST['export_config']) ? '{}' : $_POST['export_config'];
$type = static::getPostData('export_filetype', 'html');
$name = static::getPostData('export_filename', Yii::t('kvgrid', 'export'));
$content = static::getPostData('export_content', Yii::t('kvgrid', 'No data found'));
$mime = static::getPostData('export_mime', 'text/plain');
$encoding = static::getPostData('export_encoding', 'utf-8');
$config = static::getPostData('export_config', '{}');
if ($type == GridView::PDF) {
$config = Json::decode($config);
$this->generatePDF($content, "{$name}.pdf", $config);
Expand Down Expand Up @@ -87,4 +87,17 @@ protected function setHttpHeaders($type, $name, $mime, $encoding = 'utf-8')
header("Content-Disposition: attachment; filename={$name}.{$type}");
header("Cache-Control: max-age=0");
}

/**
* Gets the value of a variable in $_POST
*
* @param int|string $key the variable name in $_POST
* @param mixed $default the default value
*
* @return mixed the post data value
*/
protected static function getPostData($key, $default = null)
{
return empty($_POST) || empty($_POST[$key]) ? $default : $_POST[$key];
}
}

0 comments on commit db02213

Please sign in to comment.