一个列数组yii gridview中的两个关系值(two relation values in one column array yii gridview)

编程入门 行业动态 更新时间:2024-10-25 18:29:12
一个列数组yii gridview中的两个关系值(two relation values in one column array yii gridview)

如何在一个列数组值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.

更多推荐

本文发布于:2023-07-22 18:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222350.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   两个   关系   gridview   yii

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!