Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Validators that used to cause PHP error when array value is being validated now throws an exception instead of adding error message to the validated model. #2190

Closed
wants to merge 2 commits into
from

Conversation

4 participants
Contributor

resurtm commented Mar 10, 2013

Enhances #2186.
Fixes #1955.

I didn't touched array value safe validators. E.g. CBooleanValidator also is not intended to be used with arrays but it does not cause any PHP errors when array value passed to its validateAttribute().

resurtm added some commits Mar 10, 2013

@resurtm resurtm Validators that used to cause PHP error when array value is being val…
…idated now throws an exception instead of adding error message to the validated model.
5e418fc
@resurtm resurtm Indentation consistency in unit tests. d1a785f

@resurtm resurtm commented on the diff Mar 10, 2013

framework/web/helpers/CHtml.php
@@ -1585,11 +1585,6 @@ public static function activeTextArea($model,$attribute,$htmlOptions=array())
}
else
$text=self::resolveValue($model,$attribute);
-
- // https://github.com/yiisoft/yii/issues/1955
- if(is_array($text))
@resurtm

resurtm Mar 10, 2013

Contributor

Better to left as is. It's not needed anymore in this PR, so i reverted it.

Owner

samdark commented Mar 10, 2013

Discussion is in #2186

@samdark samdark closed this Mar 11, 2013

Contributor

slavcodev commented Apr 30, 2013

Why did you choose to change all validators instead of one method CValidator::validate()?

public function validate($object,$attributes=null)
{
    if(is_array($attributes))
        $attributes=array_intersect($this->attributes,$attributes);
    else
        $attributes=$this->attributes;
    foreach($attributes as $attribute)
    {
        if(!$this->skipOnError || !$object->hasErrors($attribute) || !!is_array($object->$attribute))
            $this->validateAttribute($object,$attribute);
    }
}
Owner

cebe commented Apr 30, 2013

@slavcodev have you seen the code? https://github.com/yiisoft/yii/pull/2186/files
Different validators handle the issue in different ways.
Btw: this PR has not been merged, so your comment is a bit misplaced :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment