[closed] empty value checking in CHtml::encode()

Dear Developer,

Can i put empty value checking in CHtml::encode() like:


public static function encode($text)

	{

		return htmlspecialchars($text?$text:'',ENT_QUOTES,Yii::app()->charset);

	}

or some else similar like that?

Because sometime i got an empty array returned from resolveValue() in this code


public static function activeTextArea($model,$attribute,$htmlOptions=array())

	{

		self::resolveNameID($model,$attribute,$htmlOptions);

		self::clientChange('change',$htmlOptions);

		if($model->hasErrors($attribute))

			self::addErrorCss($htmlOptions);

		$text=self::resolveValue($model,$attribute);

		return self::tag('textarea',$htmlOptions,isset($htmlOptions['encode']) && !$htmlOptions['encode'] ? $text : self::encode($text));

	}

I can also avoid the error by passing empty value of encode option in $htmlOptions parameter


array('encode'=>'')

is that recomended?

Thanks alot

what is the error you get?

The error can be seen in this picture

resolveValue returns the value of the model attribute… from the error I guess the model is Property and the attribute is headline…

you need to check the value of that attribute… it should not be an array

Thats in Create new data form, code works fine in Update data form. any solution?

How can you expect anybody will give you a solution when you don’t give enough details…

I already wrote you above that I’m guessing the attribute and it’s values… did you check those at all ?

He already wrote that he gets an empty array back from resolveValue…

ibiz4, if you get an array back from a table rows value then there is something wrong in you ActiveRecord class. You are trying to give a fix for a situation that normally should not exist.

Please give us an example of what you are doing (Code of the form an Active Record).

@all Thanks men, you are clever. Since i’m using dynamic model maybe it seem any not desired value of my virtual attribute because its value assigned using setter and getter