Skip to content

Commit

Permalink
Added yii\web\Request::get($name = null, $defaultValue = null) and …
Browse files Browse the repository at this point in the history
…`yii\web\Request::post($name = null, $defaultValue = null)`
  • Loading branch information
samdark committed Jan 28, 2014
1 parent 8c7ae47 commit f1a674b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
8 changes: 5 additions & 3 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ Yii Framework 2 Change Log
- Chg #1852: DbConnection::tablePrefix default value now 'tbl_' (creocoder)
- Chg #1958: `beforeSubmit` in `yii.activeform` is now executed after validation and before form submission (6pblcb)
- Chg #2025: Removed ability to declare scopes in ActiveRecord (samdark)
- Chg #2043: Renamed `yii\web\Request::acceptedLanguages` to `acceptableLanguages` (qiangxue)
- Chg #2043: Removed `yii\web\Request::getPost()`, `getPut()`, `getDelete()`, `getPatch()` in favor of `getBodyParam()` (cebe)
- Chg #2043: Renamed `yii\web\Request::get()` to `getQueryParams()` and `getRestParams()` to `getBodyParams()` (cebe)
- Chg #2043:
- Renamed `yii\web\Request::acceptedLanguages` to `acceptableLanguages` (qiangxue)
- Removed `yii\web\Request::getPost()`, `getPut()`, `getDelete()`, `getPatch()` in favor of `getBodyParam()` (cebe)
- Renamed `yii\web\Request::get()` to `getQueryParams()` and `getRestParams()` to `getBodyParams()` (cebe)
- Added `yii\web\Request::get($name = null, $defaultValue = null)` and `yii\web\Request::post($name = null, $defaultValue = null)` (samdark)
- Chg #2057: AutoTimestamp attributes defaults changed from `create_time` and `update_time` to `created_at` and `updated_at` (creocoder)
- Chg #2059: Implemented git-flavored file excluding/filtering for `FileHelper` (nineinchnick)
- Chg #2063: Removed `yii\web\Request::acceptTypes` and renamed `yii\web\Request::acceptedContentTypes` to `acceptableContentTypes` (qiangxue)
Expand Down
32 changes: 32 additions & 0 deletions framework/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,22 @@ public function getBodyParam($name, $defaultValue = null)
return isset($params[$name]) ? $params[$name] : $defaultValue;
}

/**
* Returns POST parameter with a given name. If name isn't specified, returns an array of all POST parameters.
*
* @param string $name the parameter name
* @param mixed $defaultValue the default parameter value if the parameter does not exist.
* @return array|mixed
*/
public function post($name = null, $defaultValue = null)
{
if ($name === null) {
return $this->getBodyParams();
} else {
return $this->getBodyParam($name, $defaultValue);
}
}

private $_queryParams;

/**
Expand Down Expand Up @@ -408,6 +424,22 @@ public function setQueryParams($values)
$this->_queryParams = $values;
}

/**
* Returns GET parameter with a given name. If name isn't specified, returns an array of all GET parameters.
*
* @param string $name the parameter name
* @param mixed $defaultValue the default parameter value if the parameter does not exist.
* @return array|mixed
*/
public function get($name = null, $defaultValue = null)
{
if ($name === null) {
return $this->getQueryParams();
} else {
return $this->getQueryParam($name, $defaultValue);
}
}

/**
* Returns the named GET parameter value.
* If the GET parameter does not exist, the second parameter to this method will be returned.
Expand Down

0 comments on commit f1a674b

Please sign in to comment.