Yii 关系,数组检查值是否存在
我正在尝试创建一个 if then 语句,以便仅在数组中存在值时显示某些内容。
给定两个表“地址”和“玩家”,我有以下关系
'displayAddress' => array(self::HAS_MANY, 'Address', 'PlayerId',
'condition'=>array('IsHome=:home', 'IsWork=:wok'),
'params' => array(':hom'=>'Y', ':wok'=>'N')),
现在在“玩家”视图中,我想检查该玩家是否有任何地址,其中只是他们的家而不是他们的工作地点。
我尝试为数组设置一个函数并检查视图中的 isset 以及 in_array() 和 array_key_exists() 但我无法解决它。
I am trying to create a if then statement to only display something if a value in a array exists.
Given two tables Address and Player I have the following relation
'displayAddress' => array(self::HAS_MANY, 'Address', 'PlayerId',
'condition'=>array('IsHome=:home', 'IsWork=:wok'),
'params' => array(':hom'=>'Y', ':wok'=>'N')),
Now in a Player view I want to check to see if that player has any addresses where it is only their home and not their work.
I have tried setting a function for the array and checking doing isset in the view as well as in_array() and array_key_exists() but I haven't been able to solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拥有的关系应该/将仅返回 IsHome=Y 和 IsWork=N 的实例。这是否按预期工作?如果没有,请尝试:
'displayAddress' =>数组(self::HAS_MANY, '地址', '玩家ID',
'条件'=>'IsHome=:home AND IsWork=:wok',
'参数' => array(':hom'=>'Y', ':wok'=>'N')),
The relation you have should / will return only instances where IsHome=Y and IsWork=N. Does this work as expected? If not, try:
'displayAddress' => array(self::HAS_MANY, 'Address', 'PlayerId',
'condition'=>'IsHome=:home AND IsWork=:wok',
'params' => array(':hom'=>'Y', ':wok'=>'N')),