php - yii自定义rules,参数传递
ringa_lee
ringa_lee 2017-04-10 17:03:25
0
1
637
    return [
        [['cat_name','unit','pid','sort','is_show','price_area'], 'required',],
        [['pid', 'sort', 'is_show', 'price_area'], 'integer'],
        [['cat_name'], 'string', 'max' => 30],
        [['unit'], 'string', 'max' => 10],
        [['des'], 'string', 'max' => 100],
         [['cat_name'], 'checkCategoryName' ,  'params' => [ 'pid' => '1',  'catgoryname'  => 'cat_name'  ]  ], //验证分类名是否合法 (同一级别下 分类名不能重复)
    ];

最后一条规则,我想把pid和 cat_name作为参数传递到 自定义的checkCategoryName($attribute, $params)中去,
但是好像只可以传递常量例如pid=1,但是为什么我传cat_name变量不行?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
洪涛

inline validator的话可以在方法中直接访问即可:

function checkCategoryName($attribute, $params) {
    $pid = $this->pid;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!