Commit 7c48837a by Qiang Xue

Fixes #5836: doc fixes.

parent 80229421
......@@ -202,6 +202,9 @@ use app\assets\AppAsset;
AppAsset::register($this); // $this represents the view object
```
> Info: The [[yii\web\AssetBundle::register()]] method returns an asset bundle object containing the information
about the published assets, such as [[yii\web\AssetBundle::basePath|basePath]] or [[yii\web\AssetBundle::baseUrl|baseUrl]].
If you are registering an asset bundle in other places, you should provide the needed view object. For example,
to register an asset bundle in a [widget](structure-widgets.md) class, you can get the view object by `$this->view`.
......@@ -212,8 +215,6 @@ listed in the registered bundles. The order of these tags is determined by the d
the registered bundles and the order of the assets listed in the [[yii\web\AssetBundle::css]] and [[yii\web\AssetBundle::js]]
properties.
> Tip: The [[yii\web\AssetBundle::register()]] method returns the registered asset bundle object, so you can use it to retrieve
> information like for example the [[yii\web\AssetBundle::basePath|basePath]] from it.
### Customizing Asset Bundles <a name="customizing-asset-bundles"></a>
......
......@@ -176,17 +176,17 @@ class Validator extends Component
* Creates a validator object.
* @param mixed $type the validator type. This can be a built-in validator name,
* a method name of the model class, an anonymous function, or a validator class name.
* @param \yii\base\Model $object the data object to be validated.
* @param \yii\base\Model $model the data model to be validated.
* @param array|string $attributes list of attributes to be validated. This can be either an array of
* the attribute names or a string of comma-separated attribute names.
* @param array $params initial values to be applied to the validator properties
* @return Validator the validator
*/
public static function createValidator($type, $object, $attributes, $params = [])
public static function createValidator($type, $model, $attributes, $params = [])
{
$params['attributes'] = $attributes;
if ($type instanceof \Closure || $object->hasMethod($type)) {
if ($type instanceof \Closure || $model->hasMethod($type)) {
// method-based validator
$params['class'] = __NAMESPACE__ . '\InlineValidator';
$params['method'] = $type;
......@@ -217,13 +217,13 @@ class Validator extends Component
/**
* Validates the specified object.
* @param \yii\base\Model $object the data object being validated
* @param \yii\base\Model $model the data model being validated
* @param array|null $attributes the list of attributes to be validated.
* Note that if an attribute is not associated with the validator,
* it will be ignored.
* If this parameter is null, every attribute listed in [[attributes]] will be validated.
*/
public function validateAttributes($object, $attributes = null)
public function validateAttributes($model, $attributes = null)
{
if (is_array($attributes)) {
$attributes = array_intersect($this->attributes, $attributes);
......@@ -231,11 +231,11 @@ class Validator extends Component
$attributes = $this->attributes;
}
foreach ($attributes as $attribute) {
$skip = $this->skipOnError && $object->hasErrors($attribute)
|| $this->skipOnEmpty && $this->isEmpty($object->$attribute);
$skip = $this->skipOnError && $model->hasErrors($attribute)
|| $this->skipOnEmpty && $this->isEmpty($model->$attribute);
if (!$skip) {
if ($this->when === null || call_user_func($this->when, $object, $attribute)) {
$this->validateAttribute($object, $attribute);
if ($this->when === null || call_user_func($this->when, $model, $attribute)) {
$this->validateAttribute($model, $attribute);
}
}
}
......@@ -244,14 +244,14 @@ class Validator extends Component
/**
* Validates a single attribute.
* Child classes must implement this method to provide the actual validation logic.
* @param \yii\base\Model $object the data object to be validated
* @param \yii\base\Model $model the data model to be validated
* @param string $attribute the name of the attribute to be validated.
*/
public function validateAttribute($object, $attribute)
public function validateAttribute($model, $attribute)
{
$result = $this->validateValue($object->$attribute);
$result = $this->validateValue($model->$attribute);
if (!empty($result)) {
$this->addError($object, $attribute, $result[0], $result[1]);
$this->addError($model, $attribute, $result[0], $result[1]);
}
}
......@@ -303,7 +303,7 @@ class Validator extends Component
* - `messages`: an array used to hold the validation error messages for the attribute.
* - `deferred`: an array used to hold deferred objects for asynchronous validation
*
* @param \yii\base\Model $object the data object being validated
* @param \yii\base\Model $model the data model being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\web\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
......@@ -311,7 +311,7 @@ class Validator extends Component
* client-side validation.
* @see \yii\widgets\ActiveForm::enableClientValidation
*/
public function clientValidateAttribute($object, $attribute, $view)
public function clientValidateAttribute($model, $attribute, $view)
{
return null;
}
......@@ -335,17 +335,17 @@ class Validator extends Component
/**
* Adds an error about the specified attribute to the model object.
* This is a helper method that performs message selection and internationalization.
* @param \yii\base\Model $object the data object being validated
* @param \yii\base\Model $model the data model being validated
* @param string $attribute the attribute being validated
* @param string $message the error message
* @param array $params values for the placeholders in the error message
*/
public function addError($object, $attribute, $message, $params = [])
public function addError($model, $attribute, $message, $params = [])
{
$value = $object->$attribute;
$params['attribute'] = $object->getAttributeLabel($attribute);
$value = $model->$attribute;
$params['attribute'] = $model->getAttributeLabel($attribute);
$params['value'] = is_array($value) ? 'array()' : $value;
$object->addError($attribute, Yii::$app->getI18n()->format($message, $params, Yii::$app->language));
$model->addError($attribute, Yii::$app->getI18n()->format($message, $params, Yii::$app->language));
}
/**
......
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