Errorsummary Not Showing

Errorsummay is showing fine on action create. But with update action model validates fine but error summary is never shown. It’s driving me crazy… Any help?




class alunos extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return alunos the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'app_alunos';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.




		return array(

			array('id, nome, morada, sexo, email, login, dataentrada, datanascimento, concelho, 

             modofinanciamento, areafreq, escfrequentada, nacionalidade, docid', 'required'),

			array('desativado, concelho, modofinanciamento, areafreq, escfrequentada', 'numerical', 'integerOnly'=>true),

			array('nome, morada', 'length', 'max'=>200),

			array('notas', 'length', 'max'=>1000),

      array('id', 'length', 'max'=>10),

      array('id','unique','message'=>'{attribute}:{value} já existe!'),

      array('login','unique','message'=>'{attribute}:{value} já existe!'),

			array('nacionalidade', 'length', 'max'=>2),

			array('email, login', 'length', 'max'=>100),

      array('email', 'email'),

			array('docid', 'length', 'max'=>50),

			array('telfixo, telemovel', 'length', 'max'=>30),

			array('filefoto', 'length', 'max'=>300),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, nome, morada, sexo, email, login, dataentrada, datanascimento, concelho, 

            modofinanciamento, areafreq, escfrequentada, nacionalidade, docid,

            relConcelho, relPais, notas, relModoFinanciamento,relEscolaSec, relAreaFreq, 

            desativado, telfixo, telemovel, filefoto', 'safe', 'on'=>'search'),

		);

	}




	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		

    return array(

     'relConcelho' => array(self::BELONGS_TO, 'concelhos', 'concelho'),

     'relPais' => array(self::BELONGS_TO, 'paises', 'nacionalidade'),

     'relModoFinanciamento' => array(self::BELONGS_TO, 'modosfinanciamento', 'modofinanciamento'),

     'relAreaFreq' => array(self::BELONGS_TO, 'areasentrada', 'areafreq'),

     'relEscolaSec' => array(self::BELONGS_TO, 'escolassecundarias', 'escfrequentada'),

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'Número',

			'nome' => 'Nome',

			'morada' => 'Morada',

			'nacionalidade' => 'Nacionalidade',

			'email' => 'Email',

			'dataentrada' => 'Data de Entrada',

			'desativado' => 'Desat?',

			'login' => 'Login',

			'docid' => 'Doc.Ident.',

			'telfixo' => 'Tel.Fixo',

			'telemovel' => 'Tel.Móvel',

			'concelho' => 'Concelho',

      'relConcelho.nome' => 'Concelho',

      'relConcelho' => 'Concelho',

      'datanascimento' => 'Dt. Nasc.',

      'modofinanciamento'  => 'Modo Fin.',

      'areafreq'  => 'Area Freq.',

      'escfrequentada'  => 'Escola Frequentada',

      'sexo' => 'Sexo',

			'filefoto' => 'Foto',

      'relPais.pais' => 'Nacionalidade',

      'relModoFinanciamento.nome' => 'Modo de Financiamento',

      'relAreaFreq.nome' => 'Área de Entrada',

      'relEscolaSec.nome' => 'Esc.Sec. Frequentada',

      'notas' => 'Observações',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('t.id',$this->id);

		$criteria->compare('t.nome',$this->nome,true);

		$criteria->compare('morada',$this->morada,true);

		$criteria->compare('nacionalidade',$this->nacionalidade,true);

		$criteria->compare('email',$this->email,true);

		$criteria->compare('notas',$this->notas,true);

		$criteria->compare('dataentrada',$this->dataentrada,true);

		$criteria->compare('desativado',$this->desativado);

		$criteria->compare('login',$this->login,true);

		$criteria->compare('docid',$this->docid,true);

		$criteria->compare('telfixo',$this->telfixo,true);

		$criteria->compare('telemovel',$this->telemovel,true);

    $criteria->compare('sexo',$this->sexo,true);

		$criteria->compare('concelho',$this->concelho);

		$criteria->compare('filefoto',$this->filefoto,true);


    $criteria->with = array( 'relConcelho');

    $criteria->compare( 'relConcelho.nome', $this->relConcelho, true );


    $criteria->with = array( 'relPais');

    $criteria->compare( 'relPais.pais', $this->relPais, true );


    $criteria->with = array( 'relModoFinanciamento');

    $criteria->compare( 'relModoFinanciamento.nome', $this->relModoFinanciamento, true );


    $criteria->with = array( 'relEscolaSec');

    $criteria->compare( 'relEscolaSec.nome', $this->relEscolaSec, true );


    $criteria->with = array( 'relAreaFreq');

    $criteria->compare( 'relAreaFreq.nome', $this->relAreaFreq, true );




    $criteria->compare('datanascimento',$this->datanascimento,true); 

    $criteria->compare('modofinanciamento',$this->modofinanciamento,true);

    $criteria->compare('escfrequentada',$this->escfrequentada,true);

    $criteria->compare('areafreq',$this->areafreq,true);

    $criteria->compare('sexo',$this->sexo,true);

    

    $sorter = new CSort;        

    $sorter->defaultOrder = 't.id';        

    $sorter->attributes = array(

        'id'=>'t.id',

        'datanascimento'=>'datanascimento',

        'nome'=>'nome',

        'relConcelho'=>array('asc'=>'relConcelho.nome','desc'=>'relConcelho.nome DESC',),

        );


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

      'sort'=>$sorter,

			'pagination'=>array('pageSize'=>50), 

		));

	}



controler




<?php


class AlunosController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='//layouts/column2';


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

			'postOnly + delete', // we only allow deletion via POST request

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow', 'actions'=>array('create'),  'expression'=>'utils::checkPermission(55)',),

			array('allow', 'actions'=>array('update'),  'expression'=>'utils::checkPermission(55)',),

			array('allow', 'actions'=>array('view'),    'expression'=>'utils::checkPermission(55)',),      

			array('allow', 'actions'=>array('index'),   'expression'=>'utils::checkPermission(55)',),

			array('allow', 'actions'=>array('delete'),  'expression'=>'utils::checkPermission(55)',),

      array('allow', 'actions'=>array('excel'),   'expression'=>'utils::checkPermission(55)',),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


	/**

	 * Displays a particular model.

	 * @param integer $id the ID of the model to be displayed

	 */

	public function actionView($id)

	{


        $this->render('view', array(

           'model'=>$this->loadModel($id),

         ));

    

    utils::regista('Alunos', 'Consultou a ficha do aluno:'.$id);

	}


	/**

	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.

	 */

	public function actionCreate()

	{

		$model=new alunos;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['alunos']))

		{

			$model->attributes=$_POST['alunos'];

			if($model->save()):

        utils::regista('Alunos', 'Criou novo aluno. Id:'.$model->id);

				$this->redirect(array('index','id'=>$model->id));

      endif;  

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}


	/**

	 * Updates a particular model.

	 * If update is successful, the browser will be redirected to the 'view' page.

	 * @param integer $id the ID of the model to be updated

	 */

	public function actionUpdate($id)

	{

    $model=$this->loadModel($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['alunos'])):	

			$model->attributes=$_POST['alunos'];

      if($model->save()):

        utils::regista('Alunos', 'Modificou o Aluno '.$model->id);

				$this->redirect(array('index','id'=>$model->id));

      endif;  

		endif;

    

    $this->render('update', array('model'=>$this->loadModel($id),));

        

    

  }


	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'admin' page.

	 * @param integer $id the ID of the model to be deleted

	 */

	public function actionDelete($id)

	{

		try {

      $this->loadModel($id)->delete();

      utils::regista('Alunos', 'Apagou o Aluno de ID:'.$id);	

  		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

  		if(!isset($_GET['ajax'])):

  			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));

      endif;

    }

    catch (Exception $e) {

      throw new CHttpException('','Não foi possível apagar o Aluno. Provavelmente existem dados dependentes.');

    }

 }


	/**

	 * Manages all models.

	 */

	public function actionIndex()

	{

		$model=new alunos('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['alunos']))

			$model->attributes=$_GET['alunos'];


		$this->render('admin',array(

			'model'=>$model,

		));


    utils::regista('Alunos', 'Consultou ficheiro de alunos');

	}


	/**

	 * Returns the data model based on the primary key given in the GET variable.

	 * If the data model is not found, an HTTP exception will be raised.

	 * @param integer $id the ID of the model to be loaded

	 * @return alunos the loaded model

	 * @throws CHttpException

	 */

	public function loadModel($id)

	{

		$model=alunos::model()->findByPk($id);

		if($model===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $model;

	}


	/**

	 * Performs the AJAX validation.

	 * @param alunos $model the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='alunos-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

	}

}




form:




<?php

/* @var $this AlunosController */

/* @var $model alunos */

/* @var $form CActiveForm */

?>


<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'alunos-form',

	'enableAjaxValidation'=>true,

)); ?>


	<p class="note"><?php echo Yii::t('seguranca','Fields with'); ?> 

            <span class="required">*</span> <?php echo Yii::t('seguranca','are required'); ?> .</p>


	<?php echo $form->errorSummary($model); ?>


  <div class="row">

		<?php echo $form->labelEx($model,'id'); ?>

		<?php echo $form->textField($model,'id',array('size'=>60,'maxlength'=>200)); ?>

		<?php echo $form->error($model,'id'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'nome'); ?>

		<?php echo $form->textField($model,'nome',array('size'=>60,'maxlength'=>200)); ?>

		<?php echo $form->error($model,'nome'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'morada'); ?>

		<?php echo $form->textField($model,'morada',array('size'=>60,'maxlength'=>200)); ?>

		<?php echo $form->error($model,'morada'); ?>

	</div>


  <div class="row">

		<?php echo $form->labelEx($model,'nacionalidade'); ?>

		<?php echo $form->dropDownList($model, 'nacionalidade', 

		           CHtml::listData(paises::model()->findAll(array('order'=>'pais')), 'sigla', 'pais'),

		           array('prompt' => 'Escolha o País',)		

		); ?>

		<?php echo $form->error($model,'nacionalidade'); ?>

  </div>


	<div class="row">

		<?php echo $form->labelEx($model,'email'); ?>

		<?php echo $form->textField($model,'email',array('size'=>60,'maxlength'=>100)); ?>

		<?php echo $form->error($model,'email'); ?>

	</div>


  <div class="row">

      <?php echo $form->labelEx($model,'datanascimento'); ?>

      <?php $this->widget('application.extensions.jui.EDatePicker',

        array(

         'name'=>'datanascimento',

         'attribute'=>'datanascimento', // Model attribute filed which hold user input

         'model'=>$model,            // Model name

         'language'=>'pt-BR',

         'mode'=>'imagebutton',

         'theme'=>'cupertino',

         'value'=>date('d-m-Y'),

         'htmlOptions'=>array('size'=>10),

         'fontSize'=>'0.8em'

         ));?>	

  	  <?php echo $form->error($model,'datanascimento'); ?>

  </div>


  <div class="row">

		<?php echo $form->labelEx($model,'sexo'); ?>

    <?php echo $form->dropDownList($model, 'sexo',

                      array('F'=>'Feminino','M'=>'Masculino',)

                      ); ?>

		<?php echo $form->error($model,'sexo'); ?>

  </div>


  <div class="row">

		<?php echo $form->labelEx($model,'concelho'); ?>

		<?php echo $form->dropDownList($model, 'concelho', 

		           CHtml::listData(concelhos::model()->findAll(array('order'=>'nome')), 'id', 'nome'),

		           array('prompt' => 'Escolha o Concelho',)		

		); ?>

		<?php echo $form->error($model,'concelho'); ?>

  </div>


  <div class="row">

		<?php echo $form->labelEx($model,'escfrequentada'); ?>

		<?php echo $form->dropDownList($model, 'escfrequentada', 

		           CHtml::listData(escolassecundarias::model()->findAll(array('order'=>'nome')), 'id', 'nome'),

		           array('prompt' => 'Escolha a Escola',)		

		); ?>

		<?php echo $form->error($model,'escfrequentada'); ?>

  </div>


  <div class="row">

		<?php echo $form->labelEx($model,'areafreq'); ?>

		<?php echo $form->dropDownList($model, 'areafreq', 

		           CHtml::listData(areasentrada::model()->findAll(array('order'=>'nome')), 'id', 'nome'),

		           array('prompt' => 'Escolha a Área',)		

		); ?>

		<?php echo $form->error($model,'areafreq'); ?>

  </div>


  <div class="row">

		<?php echo $form->labelEx($model,'modofinanciamento'); ?>

		<?php echo $form->dropDownList($model, 'modofinanciamento', 

		           CHtml::listData(modosfinanciamento::model()->findAll(array('order'=>'nome')), 'id', 'nome'),

		           array('prompt' => 'Escolha o Modo',)		

		); ?>

		<?php echo $form->error($model,'modofinanciamento'); ?>

  </div>


	<div class="row">

		<?php echo $form->labelEx($model,'desativado'); ?>

    <?php echo $form->checkBox($model,'desativado',array('value' => '1', 'uncheckValue'=>'0')); ?>

		<?php echo $form->error($model,'desativado'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'docid'); ?>

		<?php echo $form->textField($model,'docid',array('size'=>50,'maxlength'=>50)); ?>

		<?php echo $form->error($model,'docid'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'telfixo'); ?>

		<?php echo $form->textField($model,'telfixo',array('size'=>30,'maxlength'=>30)); ?>

		<?php echo $form->error($model,'telfixo'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'telemovel'); ?>

		<?php echo $form->textField($model,'telemovel',array('size'=>30,'maxlength'=>30)); ?>

		<?php echo $form->error($model,'telemovel'); ?>

	</div>


  <div class="row">

		<?php echo $form->labelEx($model,'login'); ?>

		<?php echo $form->textField($model,'login',array('size'=>60,'maxlength'=>100)); ?>

		<?php echo $form->error($model,'login'); ?>

	</div>

  

	<div class="row">

		<?php echo $form->labelEx($model,'filefoto'); ?>

		<?php echo $form->textField($model,'filefoto',array('size'=>60,'maxlength'=>300)); ?>

		<?php echo $form->error($model,'filefoto'); ?>

	</div>


  <div class="row">

      <?php echo $form->labelEx($model,'dataentrada'); ?>

      <?php $this->widget('application.extensions.jui.EDatePicker',

        array(

         'name'=>'dataentrada',

         'attribute'=>'dataentrada', // Model attribute filed which hold user input

         'model'=>$model,            // Model name

         'language'=>'pt-BR',

         'mode'=>'imagebutton',

         'theme'=>'cupertino',

         'value'=>date('d-m-Y'),

         'htmlOptions'=>array('size'=>10),

         'fontSize'=>'0.8em'

         ));?>	

  	  <?php echo $form->error($model,'dataentrada'); ?>

  </div>




  <div class="row">

		<?php echo $form->labelEx($model,'notas'); ?>

		<?php echo $form->textArea($model,'notas',array('rows'=>6, 'cols'=>50)); ?>

		<?php echo $form->error($model,'notas'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Criar' : 'Gravar'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- form -->




Fixed. To who ever has the same problem:

In controller I was doing


$this->render('update', array('model'=>$this->loadModel($id),));

instead of


$this->render('update', array('model'=>$model,));