From 785b027dbf17fa4a90e45c19c97d58fd6b8c254e Mon Sep 17 00:00:00 2001 From: Qiang Xue <qiang.xue@gmail.com> Date: Wed, 18 Jun 2014 17:45:10 -0400 Subject: [PATCH] doc update [skip ci] --- framework/behaviors/SluggableBehavior.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/framework/behaviors/SluggableBehavior.php b/framework/behaviors/SluggableBehavior.php index 4b4113c..c55f46d 100644 --- a/framework/behaviors/SluggableBehavior.php +++ b/framework/behaviors/SluggableBehavior.php @@ -12,7 +12,7 @@ use yii\db\BaseActiveRecord; 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: * @@ -25,6 +25,7 @@ use yii\helpers\Inflector; * [ * 'class' => SluggableBehavior::className(), * 'attribute' => 'title', + * // 'slugAttribute' => 'slug', * ], * ]; * } @@ -36,13 +37,26 @@ use yii\helpers\Inflector; class SluggableBehavior extends AttributeBehavior { /** - * @var string + * @var string the attribute that will receive the slug value */ public $slugAttribute = 'slug'; /** - * @var string + * @var string the attribute whose value will be converted into a slug */ 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 @@ -56,7 +70,7 @@ class SluggableBehavior extends AttributeBehavior } 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.'); } } -- libgit2 0.27.1