Yii Framework Forum: [closed] empty value checking in CHtml::encode() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   ibiz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 26-November 10
  • Location:Indonesia

Posted 22 January 2012 - 02:14 AM

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
WYSIWYG
(What Yii Serve is What You Get)
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,340
  • Joined: 12-October 09
  • Location:Croatia

Posted 22 January 2012 - 03:19 AM

what is the error you get?
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   ibiz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 26-November 10
  • Location:Indonesia

Posted 22 January 2012 - 05:11 AM

View Postmdomba, on 22 January 2012 - 03:19 AM, said:

what is the error you get?

The error can be seen in this picture
http://i.imgur.com/tua4z.png
WYSIWYG
(What Yii Serve is What You Get)
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,340
  • Joined: 12-October 09
  • Location:Croatia

Posted 22 January 2012 - 02:49 PM

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
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   ibiz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 26-November 10
  • Location:Indonesia

Posted 22 January 2012 - 07:44 PM

View Postmdomba, on 22 January 2012 - 02:49 PM, said:

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?
WYSIWYG
(What Yii Serve is What You Get)
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,340
  • Joined: 12-October 09
  • Location:Croatia

Posted 23 January 2012 - 05:23 AM

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 ?
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 480
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 23 January 2012 - 06:30 AM

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).
0

#8 User is offline   ibiz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 26-November 10
  • Location:Indonesia

Posted 23 January 2012 - 06:35 PM

@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
WYSIWYG
(What Yii Serve is What You Get)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users