Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two relation values in one column array yii gridview

Tags:

yii

how to display two relation values in one column array values gridview yii

in my model code with relation

$criteria->compare('exp.ExperienceYear',$this->Experience, true);
 $criteria->compare('exp.ExperienceMonth',$this->Experience, true);

in my gridview column array code

array( 
                 'name' => 'Experience',
                 'type' => 'raw',
                    'value'=> '(empty($data->exp->ExperienceYear))? "" : Yii::app()->params["currencySymbol"]." ".$data->exp->ExperienceYear.\'-\'.(empty($data->exp->ExperienceMonth))? "" : Yii::app()->params["currencySymbol"]." ".$data->exp->ExperienceMonth' ,

           ), 

its not displaying two relation values in one field

like image 550
murugan Avatar asked Dec 01 '25 02:12

murugan


1 Answers

I think that problem here is that you should add extra brackets around your ternary operations. They have a very "annoying" way of resulting in unexpected behavior with more than one

array( 
   'name' => 'Experience',
   'type' => 'raw',
   'value'=> '(empty($data->exp->ExperienceYear)? "" : Yii::app()->params["currencySymbol"]." ".$data->exp->ExperienceYear.\'-\') . (empty($data->exp->ExperienceMonth)? "" : Yii::app()->params["currencySymbol"]." ".$data->exp->ExperienceMonth)' ,
), 

As you can see, I've moved the closing bracket of your empty condition to the end of each ternary operation to fully enclose it. IMO that should solve the problem.

like image 125
Blizz Avatar answered Dec 04 '25 03:12

Blizz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!