common/utilities/AjaxUtil.php
public static function generateErrorMessage( $source, $config = [] ) {

		$multiple		= isset( $config[ 'multiple' ] ) ? $config[ 'multiple' ] : false;
		$variable		= isset( $config[ 'variable' ] ) ? $config[ 'variable' ] : false;
		$modelClass		= isset( $config[ 'modelClass' ] ) ? $config[ 'modelClass' ] : null;
		$modelErrors	= [];

		// Multiple instances of same Class
		if( $multiple ) {

			foreach( $source as $idx => $model ) {

				$errors			= $model->getErrors();
				$modelClass		= isset( $modelClass ) ? $modelClass : $model->getClassName();
				$modelErrors	= [];

				foreach( $errors as $key => $value ) {

					$modelErrors[ "$modelClass[$idx][$key]" ] = $value[ 0 ];
				}
			}
		}
		// Models of different class
		else if( $variable ) {

			foreach( $source as $idx => $model ) {

				$errors			= $model->getErrors();
				$modelClass		= $model->getClassName();
				$modelErrors	= [];

				foreach( $errors as $key => $value ) {

					$modelErrors[ "{$modelClass}[$key]" ] = $value[ 0 ];
				}
			}
		}
		else {

			$errors			= $source->getErrors();
			$modelClass		= isset( $modelClass ) ? $modelClass : $source->getClassName();
			$modelErrors	= [];

			foreach( $errors as $key => $value ) {

				$modelErrors[ "{$modelClass}[$key]" ] = $value[ 0 ];
			}
		}

		return $modelErrors;
	}
public static function generateErrorMessage( $source, $config = [] ) {

		$multiple		= isset( $config[ 'multiple' ] ) ? $config[ 'multiple' ] : false;
		$variable		= isset( $config[ 'variable' ] ) ? $config[ 'variable' ] : false;
		$modelClass		= isset( $config[ 'modelClass' ] ) ? $config[ 'modelClass' ] : null;
		$modelErrors	= [];

		// Multiple instances of same Class
		if( $multiple ) {

			foreach( $source as $idx => $model ) {

				$errors			= $model->getErrors();
				$modelClass		= isset( $modelClass ) ? $modelClass : $model->getClassName();
				$modelErrors	= [];

				foreach( $errors as $key => $value ) {

					$modelErrors[ "$modelClass[$idx][$key]" ] = $value[ 0 ];
				}
			}
		}
		// Models of different class
		else if( $variable ) {

			foreach( $source as $idx => $model ) {

				$errors			= $model->getErrors();
				$modelClass		= $model->getClassName();
				$modelErrors	= [];

				foreach( $errors as $key => $value ) {

					$modelErrors[ "{$modelClass}[$key]" ] = $value[ 0 ];
				}
			}
		}
		else {

			$errors			= $source->getErrors();
			$modelClass		= isset( $modelClass ) ? $modelClass : $source->getClassName();
			$modelErrors	= [];

			foreach( $errors as $key => $value ) {

				$modelErrors[ "{$modelClass}[$key]" ] = $value[ 0 ];
			}
		}

		return $modelErrors;
	}
public static function generateErrorMessage ( $ source , $ config = [ ] ) { $ multiple = isset ( $ config [ 'multiple' ] ) ? $ config [ 'multiple' ] : false ; $ variable = isset ( $ config [ 'variable' ] ) ? $ config [ 'variable' ] : false ; $ modelClass = isset ( $ config [ 'modelClass' ] ) ? $ config [ 'modelClass' ] : null ; $ modelErrors = [ ] ; // Multiple instances of same Class if ( $ multiple ) { foreach ( $ source as $ idx => $ model ) { $ errors = $ model -> getErrors ( ) ; $ modelClass = isset ( $ modelClass ) ? $ modelClass : $ model -> getClassName ( ) ; $ modelErrors = [ ] ; foreach ( $ errors as $ key => $ value ) { $ modelErrors [ "$modelClass[$idx][$key]" ] = $ value [ 0 ] ; } } } // Models of different class else if ( $ variable ) { foreach ( $ source as $ idx => $ model ) { $ errors = $ model -> getErrors ( ) ; $ modelClass = $ model -> getClassName ( ) ; $ modelErrors = [ ] ; foreach ( $ errors as $ key => $ value ) { $ modelErrors [ "{$modelClass}[$key]" ] = $ value [ 0 ] ; } } } else { $ errors = $ source -> getErrors ( ) ; $ modelClass = isset ( $ modelClass ) ? $ modelClass : $ source -> getClassName ( ) ; $ modelErrors = [ ] ; foreach ( $ errors as $ key => $ value ) { $ modelErrors [ "{$modelClass}[$key]" ] = $ value [ 0 ] ; } } return $ modelErrors ; }
The method generate an array of error messages from model validated by Yii.
@param model
@return array - error messages
The method generate an array of error messages from model validated by Yii .