Commit 617de8ac by Qiang Xue

Merge branch 'master' of github.com:yiisoft/yii2

parents 31819641 a047bec9
......@@ -110,6 +110,19 @@ Validates that the attribute value is among a list of values.
- `strict` whether the comparison is strict (both type and value must be the same). _(false)_
- `not` whether to invert the validation logic. _(false)_
### `inline`: [[InlineValidator]]
Uses a custom function to validate the attribute. You need to define a public method in your model class which will evaluate the validity of the attribute. For example, if an attribute needs to be divisible by 10. In the rules you would define: `['attributeName', 'myValidationMethod'],`.
Then, your own method could look like this:
```php
public function myValidationMethod($attribute) {
if(($attribute % 10) != 0) {
$this->addError($attribute, 'cannot divide value by 10');
}
}
```
### `integer`: [[NumberValidator]]
Validates that the attribute value is an integer number.
......
......@@ -21,6 +21,7 @@ Yii Framework 2 Change Log
- Enh: Added `favicon.ico` and `robots.txt` to defauly application templates (samdark)
- Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue)
- Enh: Support for file aliases in console command 'message' (omnilight)
- Enh: Sort and Paginiation can now create absolute URLs (cebe)
- Chg: Renamed yii\jui\Widget::clientEventsMap to clientEventMap (qiangxue)
- New #1438: [MongoDB integration](https://github.com/yiisoft/yii2-mongodb) ActiveRecord and Query (klimov-paul)
- New #1393: [Codeception testing framework integration](https://github.com/yiisoft/yii2-codeception) (Ragazzo)
......
......@@ -91,6 +91,11 @@ class Pagination extends Object
*/
public $params;
/**
* @var \yii\web\UrlManager the URL manager used for creating pagination URLs. If not set,
* the "urlManager" application component will be used.
*/
public $urlManager;
/**
* @var boolean whether to check if [[page]] is within valid range.
* When this property is true, the value of [[page]] will always be between 0 and ([[pageCount]]-1).
* Because [[pageCount]] relies on the correct value of [[totalCount]] which may not be available
......@@ -167,11 +172,12 @@ class Pagination extends Object
* Creates the URL suitable for pagination with the specified page number.
* This method is mainly called by pagers when creating URLs used to perform pagination.
* @param integer $page the zero-based page number that the URL should point to.
* @param boolean $absolute whether to create an absolute URL. Defaults to `false`.
* @return string the created URL
* @see params
* @see forcePageVar
*/
public function createUrl($page)
public function createUrl($page, $absolute = false)
{
if (($params = $this->params) === null) {
$request = Yii::$app->getRequest();
......@@ -183,7 +189,12 @@ class Pagination extends Object
unset($params[$this->pageVar]);
}
$route = $this->route === null ? Yii::$app->controller->getRoute() : $this->route;
return Yii::$app->getUrlManager()->createUrl($route, $params);
$urlManager = $this->urlManager === null ? Yii::$app->getUrlManager() : $this->urlManager;
if ($absolute) {
return $urlManager->createAbsoluteUrl($route, $params);
} else {
return $urlManager->createUrl($route, $params);
}
}
/**
......
......@@ -329,12 +329,13 @@ class Sort extends Object
* For example, if the current page already sorts the data by the specified attribute in ascending order,
* then the URL created will lead to a page that sorts the data by the specified attribute in descending order.
* @param string $attribute the attribute name
* @param boolean $absolute whether to create an absolute URL. Defaults to `false`.
* @return string the URL for sorting. False if the attribute is invalid.
* @throws InvalidConfigException if the attribute is unknown
* @see attributeOrders
* @see params
*/
public function createUrl($attribute)
public function createUrl($attribute, $absolute = false)
{
if (($params = $this->params) === null) {
$request = Yii::$app->getRequest();
......@@ -343,7 +344,11 @@ class Sort extends Object
$params[$this->sortVar] = $this->createSortVar($attribute);
$route = $this->route === null ? Yii::$app->controller->getRoute() : $this->route;
$urlManager = $this->urlManager === null ? Yii::$app->getUrlManager() : $this->urlManager;
return $urlManager->createUrl($route, $params);
if ($absolute) {
return $urlManager->createAbsoluteUrl($route, $params);
} else {
return $urlManager->createUrl($route, $params);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment