Browse Source

added support to parse json request to Request::getRestParams()

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
7ae8b8b50f
  1. 1
      framework/CHANGELOG.md
  2. 3
      framework/web/Request.php

1
framework/CHANGELOG.md

@ -86,6 +86,7 @@ Yii Framework 2 Change Log
- Enh: Added `TableSchema::fullName` property (qiangxue)
- Enh #1839: Added support for getting file extension and basename from uploaded file (anfrantic)
- Enh: yii\codeception\TestCase now supports loading and using fixtures via Yii fixture framework (qiangxue)
- Enh: Added support to parse json request data to Request::getRestParams() (cebe)
- Chg #1519: `yii\web\User::loginRequired()` now returns the `Response` object instead of exiting the application (qiangxue)
- Chg #1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default (qiangxue)
- Chg #1610: `Html::activeCheckboxList()` and `Html::activeRadioList()` will submit an empty string if no checkbox/radio is selected (qiangxue)

3
framework/web/Request.php

@ -10,6 +10,7 @@ namespace yii\web;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\helpers\Json;
use yii\helpers\Security;
use yii\helpers\StringHelper;
@ -256,6 +257,8 @@ class Request extends \yii\base\Request
if ($this->_restParams === null) {
if (isset($_POST[$this->restVar])) {
$this->_restParams = $_POST;
} elseif(strncmp($this->getContentType(), 'application/json', 16) === 0) {
$this->_restParams = Json::decode($this->getRawBody(), true);
} else {
$this->_restParams = [];
mb_parse_str($this->getRawBody(), $this->_restParams);

Loading…
Cancel
Save