# yii验证规则根据不同规则提示不同的错误

**URL:** <https://www.shiqidu.com/t/topic/379>\
**Category:** 开发调优\
**Tags:** PHP\
**Created:** [2018 年3 月 27 日 10:25 UTC](https://www.shiqidu.com/t/topic/379 "2018-03-27T10:25:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![dajiang](https://www.shiqidu.com/user_avatar/www.shiqidu.com/dajiang/32/468_2.png) [@dajiang](https://www.shiqidu.com/u/dajiang)\
发布日期： [2018 年3 月 27 日 10:25 UTC](https://www.shiqidu.com/t/topic/379/1 "2018-03-27T10:25:43Z")

</div>

### 开始你的创作吧。

```
$rules[] = Model::addRule(\'category_sn\', \'category_name\', \'unique\', [  
			\'params\' =&gt; [  
				\'category_type\'  
			],   
			\'message\' =&gt; \'此类别{attribute}已存在\',  
			\'filter\' =&gt; [  
				\'and\',   
				[  
					\'=\',   
					\'is_deleted\',   
					0  
				],   
				[  
					\'=\',   
					\'category_type\',   
					$this-&gt;category_type  
				],  
			]  
		]);  

```

使用{attribute}属性
