Commit 785b027d by Qiang Xue

doc update [skip ci]

parent ff66c02c
...@@ -12,7 +12,7 @@ use yii\db\BaseActiveRecord; ...@@ -12,7 +12,7 @@ use yii\db\BaseActiveRecord;
use yii\helpers\Inflector; use yii\helpers\Inflector;
/** /**
* SluggableBehavior automatically fills the specified attribute with the transliterated and adjusted version to use in URLs. * SluggableBehavior automatically fills the specified attribute with a value that can be used a slug in a URL.
* *
* To use SluggableBehavior, insert the following code to your ActiveRecord class: * To use SluggableBehavior, insert the following code to your ActiveRecord class:
* *
...@@ -25,6 +25,7 @@ use yii\helpers\Inflector; ...@@ -25,6 +25,7 @@ use yii\helpers\Inflector;
* [ * [
* 'class' => SluggableBehavior::className(), * 'class' => SluggableBehavior::className(),
* 'attribute' => 'title', * 'attribute' => 'title',
* // 'slugAttribute' => 'slug',
* ], * ],
* ]; * ];
* } * }
...@@ -36,13 +37,26 @@ use yii\helpers\Inflector; ...@@ -36,13 +37,26 @@ use yii\helpers\Inflector;
class SluggableBehavior extends AttributeBehavior class SluggableBehavior extends AttributeBehavior
{ {
/** /**
* @var string * @var string the attribute that will receive the slug value
*/ */
public $slugAttribute = 'slug'; public $slugAttribute = 'slug';
/** /**
* @var string * @var string the attribute whose value will be converted into a slug
*/ */
public $attribute; public $attribute;
/**
* @var string|callable the value that will be used as a slug. This can be an anonymous function
* or an arbitrary value. If the former, the return value of the function will be used as a slug.
* The signature of the function should be as follows,
*
* ```php
* function ($event)
* {
* // return slug
* }
* ```
*/
public $value;
/** /**
* @inheritdoc * @inheritdoc
...@@ -56,7 +70,7 @@ class SluggableBehavior extends AttributeBehavior ...@@ -56,7 +70,7 @@ class SluggableBehavior extends AttributeBehavior
} }
if ($this->attribute === null && $this->value === null) { if ($this->attribute === null && $this->value === null) {
throw new InvalidConfigException('Either "attribute" or "value" properties must be specified.'); throw new InvalidConfigException('Either "attribute" or "value" property must be specified.');
} }
} }
......
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