Skip to content

Commit

Permalink
Merge pull request #360 from maxxer/allow-run-from-console
Browse files Browse the repository at this point in the history
Check for web request before accessing `post()`
  • Loading branch information
kartik-v authored Jun 15, 2022
2 parents ffae06b + 71d4706 commit e720dcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Change Log: `yii2-export`
**Date:** _under development_

- (enh #355): Correct dropdown init for Bootstrap v5.x.
- (enh #360): Check for web context before accessing `post()`

## version 1.4.2

Expand Down Expand Up @@ -305,4 +306,4 @@ Change Log: `yii2-export`

**Date:** 17-Dec-2014

- Initial release
- Initial release
17 changes: 12 additions & 5 deletions src/ExportMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,13 @@ class ExportMenu extends GridView
/**
* @var string the data output format type. Defaults to `ExportMenu::FORMAT_EXCEL_X`.
*/
private $_exportType;
protected $_exportType;

/**
* @var boolean private flag that will use $_POST [[exportRequestParam]] setting if available or use the
* [[triggerDownload]] setting
*/
private $_triggerDownload;
protected $_triggerDownload;

/**
* Appends slash to path if it does not exist
Expand Down Expand Up @@ -860,16 +860,23 @@ protected function initSettings()
}
$this->_columnSelectorEnabled = $this->showColumnSelector && $this->asDropdown;
$request = Yii::$app->request;
$this->_triggerDownload = $request->post($this->exportRequestParam, $this->triggerDownload);
$this->_exportType = $request->post($this->exportTypeParam, $this->exportType);
if ($request instanceof \yii\web\Request) {
$this->_triggerDownload = $request->post($this->exportRequestParam, $this->triggerDownload);
$this->_exportType = $request->post($this->exportTypeParam, $this->exportType);
} else {
$this->_triggerDownload = $this->triggerDownload;
$this->_exportType = $this->exportType;
}
if (!$this->stream) {
$this->target = self::TARGET_SELF;
}
if ($this->_triggerDownload) {
if ($this->stream) {
Yii::$app->controller->layout = false;
}
$this->_columnSelectorEnabled = $request->post($this->colSelFlagParam, $this->_columnSelectorEnabled);
$this->_columnSelectorEnabled = $request instanceof \yii\web\Request ?
$request->post($this->colSelFlagParam, $this->_columnSelectorEnabled) :
$this->_columnSelectorEnabled;
$this->initSelectedColumns();
}
if ($this->dynagrid) {
Expand Down

0 comments on commit e720dcd

Please sign in to comment.