luxint
(Steve)
April 1, 2012, 11:19pm
1
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
luxint
(Steve)
April 2, 2012, 4:41am
3
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
luxint
(Steve)
April 2, 2012, 6:54pm
4
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
mdomba
(Maurizio Domba Cerin)
April 3, 2012, 9:28am
5
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';