how can i add class to errorsummay without remove

2019-09-18 06:46发布

问题:

I'm trying to add a css class to the errorSummary() in yii framwork but after add class i have not header error default
how can i add class to errorsummay without remove header message

<?php echo  $form->errorSummary($model, '', '', array('class' => 'alert alert-error')); ?>

回答1:

Its a very simple one,

you can pass the class you need this way,

<?php echo CHtml::errorSummary($model, null, null, array('class'=>'className')); ?>

or

<?php echo  $form->errorSummary($model, null, null, array('class'=>'className')); ?>

so this will allow you add the class while you have the header.

check here for more information : http://www.yiiframework.com/doc/api/1.1/CActiveForm#errorSummary-detail

since you are passing, empty string for header it causes the header issue. default value is null for $header.

public string errorSummary(mixed $models, string $header=NULL, string $footer=NULL, array $htmlOptions=array ( ))


回答2:

you can set attribute errorMessageCssClass of class CActiveForm want:

and also errorSummary() has htmlOptions !

  public string errorSummary(mixed $models, string $header=NULL, string $footer=NULL, array $htmlOptions=array ( ))


回答3:

Adjust code like this.

echo $form->errorSummary($model,NULL,NULL,array('class'=>'alert alert-error'));


标签: css forms yii