I wan't Validate filed irritate_history
only when the field have_irritate
's value eq 1. and now i defind DependValidator
,
public function validate( Validation $validator, $attribute )
{
$data = $validator ->getData();
$depend = $this ->getOption( 'depend' )[0];
$other_value = $data[$depend[0]];
$depend_bool = false;
$operator = $depend[1];
$depend_value = $depend[2];
switch ( $operator ){
case 'eq':
$depend_bool = $depend_value == $other_value;
break;
}
if( $depend_bool === true ){
$native_ruel = $this ->getOption( 'nativeRule' );
unset( $native_ruel[1], $native_ruel[2] );
$native_ruel = array_values( $native_ruel );
$validator ->preRule( $native_ruel );
}
return true;
}
public function preRule( $rule ){
$rule = ['member_name', 'McstringValidator', 'member_name:成员名长度必须大于1|:member_name成员名长度必须小于等于50', [ 1, 50 ], 1 ];
$types = self::$types;
$field = $rule[0];
$type = empty($rule[1]) ? 'regex' : $rule[1];
$options = $this ->parseRule( $type, $rule );
//$this->add( $field, new $types[$type]['validator']($options));
//echo $types[$type]['validator'];exit;
//$this->add( $field, new $types[$type]['validator']($options));
$r = $this ->preChecking( $field, new $types[$type]['validator']($options) );
return $r;
var_dump( $m );exit;
var_dump( $types[$type]['validator'] );exit;
}
but the function preChecking
is always return false. this solution way is right? and preChecking should how use