如何在一个列数组值gridview yii中显示两个关系值
在我的模型代码中有关系
$criteria->compare('exp.ExperienceYear',$this->Experience, true); $criteria->compare('exp.ExperienceMonth',$this->Experience, true);在我的gridview列数组代码中
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' , ),它不在一个字段中显示两个关系值
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
最满意答案
我认为这里的问题是你应该在三元运算周围添加额外的括号。 他们有一种非常“烦人”的方式导致多个人的意外行为
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)' , ),正如您所看到的,我已将空条件的结束括号移动到每个三元运算的末尾,以完全包围它。 IMO应该解决问题。
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.
更多推荐
发布评论