Error Summary In Yii1.0

In this post, i added the information how to handle the error like error summary, error by attributes, adderrors, geterrors, form error etc in yii framework1.0. It is very useful for and also you.

Get Error By Attribute

Using below code, We can get the individual error by attribute name of form

	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name'); ?>
        <?php $errors=$model->getErrors("institutionnametxtid");
              if(count($errors)>0){ ?>                    
            <div class="errorMessage">Username  "<?php echo $model->text_institutename; ?>" has already been taken.</div>
        <?php } ?>

Get Errors From One Model And Assign To Another Model

I added this code from my project. When i shared the form submitted information for two different model, I got some problem to show the errors of second model. Because i used the first model in ‘_form’ and assigned the value to second model in controller. To manage the second model error, ‘getErrors()’ and ‘addErrors()’ functions are used. Using this we can assign the one model error to another model.

public function create(){
	$model_1=new Employee1;	
	$model_2=new Employee1;	

		if($model_1->validate() && $model_2->validate()){