Skip to content
Browse files

* (Fixes issue 415) Added HTML options to CHtml::errorSummary() and e…

…rror() methods.
  • Loading branch information...
1 parent 016c976 commit 185240373df30fca6e6f85fa3399aa4f80e38a2c qiang.xue committed Jun 30, 2009
Showing with 15 additions and 4 deletions.
  1. +1 −0 CHANGELOG
  2. +14 −4 framework/web/helpers/CHtml.php
View
1 CHANGELOG
@@ -23,6 +23,7 @@ Version 1.0.7 to be released
- New #378: Added support to allow dynamically turning off and on log routes (Qiang)
- New #396: Improved error display when running yiic commands (Qiang)
- New #406: Added support to allow stopping saving and deletion by an ActiveRecord behavior (Qiang)
+- New #415: Added HTML options to CHtml::errorSummary() and error() methods (Qiang)
- New: Rolled back the change about treating tinyint(1) in MySQL as boolean (Qiang)
- New: Added support for displaying call stack information in trace messages (Qiang)
- New: Added 'index' option to AR relations so that related objects can be indexed by specific column value (Qiang)
View
18 framework/web/helpers/CHtml.php
@@ -1367,11 +1367,13 @@ public static function getActiveId($model,$attribute)
* a single model or an array of models.
* @param string a piece of HTML code that appears in front of the errors
* @param string a piece of HTML code that appears at the end of the errors
+ * @param array additional HTML attributes to be rendered in the container div tag.
+ * This parameter has been available since version 1.0.7.
* @return string the error summary. Empty if no errors are found.
* @see CModel::getErrors
* @see errorSummaryCss
*/
- public static function errorSummary($model,$header=null,$footer=null)
+ public static function errorSummary($model,$header=null,$footer=null,$htmlOptions=array())
{
$content='';
if(!is_array($model))
@@ -1391,7 +1393,9 @@ public static function errorSummary($model,$header=null,$footer=null)
{
if($header===null)
$header='<p>'.Yii::t('yii','Please fix the following input errors:').'</p>';
- return self::tag('div',array('class'=>self::$errorSummaryCss),$header."\n<ul>\n$content</ul>".$footer);
+ if(!isset($htmlOptions['class']))
+ $htmlOptions['class']=self::$errorSummaryCss;
+ return self::tag('div',$htmlOptions,$header."\n<ul>\n$content</ul>".$footer);
}
else
return '';
@@ -1401,15 +1405,21 @@ public static function errorSummary($model,$header=null,$footer=null)
* Displays the first validation error for a model attribute.
* @param CModel the data model
* @param string the attribute name
+ * @param array additional HTML attributes to be rendered in the container div tag.
+ * This parameter has been available since version 1.0.7.
* @return string the error display. Empty if no errors are found.
* @see CModel::getErrors
* @see errorMessageCss
*/
- public static function error($model,$attribute)
+ public static function error($model,$attribute,$htmlOptions=array())
{
$error=$model->getError($attribute);
if($error!='')
- return self::tag('div',array('class'=>self::$errorMessageCss),$error);
+ {
+ if(!isset($htmlOptions['class']))
+ $htmlOptions['class']=self::$errorMessageCss;
+ return self::tag('div',$htmlOptions,$error);
+ }
else
return '';
}

0 comments on commit 1852403

Please sign in to comment.
Something went wrong with that request. Please try again.