How to Set Default Value On Search

Hi

I’ve added two custom searches to use in my grid view but I have a problem when there is empty data for a particular row. This happens when a subject has no parent because it is itself a parent. Instead of an empty space which is what I have at the moment I’d like to specify a default value such as ‘No Parent’ or similar.

My criteria looks like this…




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

	$criteria->compare('parent_id',$this->parent_id,false);

	$criteria->with = array('subjectName','parentName' );

	$criteria->compare('subjectName.subject', $this->subject_search,true);

	$criteria->compare('parentName.subject', $this->parent_search,true);



Does anybody know how I can accomplish this?

Thanks

Steve

See: http://www.yiiframework.com/forum/index.php/topic/8009-default-fields-values-in-cactiveform/page__p__40393__hl__+earch+default+value#entry40393

Thanks for the response Vince.

I found the ‘default’ attribute and read up on it.

I thought I’d set it up correctly but it’s still returning blank when the subject is also a parent.

Here’s my rule…





array('parent_search','default','setOnEmpty'=>true),

array('parent_search','default','value'=>'No Parent'),




Can you see any problem with my settings?

Regards

Steve

I’m still trying to solve this but am not having much success. Would appreciate any input from more experienced yii programmers.

Any ideas?

Thanks

Steve

the validation rules are processed only after the validation… so you cannot set a value before validation with them

You just need to assign the value you need before the render.

Something like


if(...)

   $model->parent_search = 'No Parent';