override core rules in yii2 -
i wanted override core rule number in yii2 convert persian numbers english numbers, , validate them? these code uses converting persian numbers english numbers in php
function convert($string) { $persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'); $num = range(0, 9); return str_replace($persian, $num, $string); }
how can apply these codes doing convert before validation?i don't want use beforevalidate in model wrote componet don't know function , should change?
add filter
rule in model.
public function rules() { return [ ['pers_number', 'filter', 'filter' => function ($value) { return str_replace( ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'], range(0, 9), $value ); }], ]; }
Comments
Post a Comment