herroffizier/yii2-attribute-index-validator
最新稳定版本:1.0.0
Composer 安装命令:
composer require herroffizier/yii2-attribute-index-validator
包简介
Yii2 validator that adds incremental index to attribute values to make them unique.
README 文档
README
This validator solves value collisions for unique model attributes by adding incremental index to repeating values. E.g. title will become title-1 if item with title already exists.
Such behavior may be useful for tasks like generating URLs and so on.
Installation
Install validator with Composer:
composer require --prefer-dist "herroffizier/yii2-attribute-index-validator:@stable"
Usage
Add validator to your model's rules array before required and unique validators (if any).
use herroffizier\yii2aiv\AttributeIndexValidator; ... public function rules() { return [ [['attribute'], AttributeIndexValidator::className()], [['attribute'], 'required'], [['attribute'], 'unique'], ]; }
Validator has a few options to customize its behavior.
separatorsets separator between original value and index. Default separator is-.startIndexdefines start index. Default value is1.filterdefines additional filter to be applied to query used to check attribute uniqueness. May be either a string, an array or an anonymous function. In case of string or arrayfiltervalue will be passed to\yii\web\ActiveQueryInterface::andWhere()method. In case of anonymous function its signature must befunction($query)and instance of\yii\web\ActiveQueryInterfacewill be passed to it. Default value isnull.
统计信息
- 总下载量: 2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-04-06