Showing posts with label Yii. Show all posts
Showing posts with label Yii. Show all posts

Friday, March 22, 2013

How to override an attribute name in yii model ?

In model add an override function for checking the errors generated on validation.

public function getErrors($attribute=null)
{
        $errors = parent::getErrors($attribute);
        if ($attribute == null) {
            // Ok We get a collection of errors
            if (isset($errors['attribute_to_be_replaces'])) {
                $error = $errors['attribute_to_be_replaces'];
                unset($errors['attribute_to_be_replaces']);
                $errors['replaced_attribute_name'] = $error;
            }
        }
        return $errors;
 }