返回的视图数据中不可预测的 CCK 字段名称
我使用 views_get_view_result
直接访问视图中的数据。我偶然发现了这种奇怪的行为,其中 cck 字段以第一个字段名称为前缀作为查询优化。 此处解释。
但奇怪的是,字段的命名不同,具体取决于我是否检索该字段以匿名或管理员身份提供数据。我很确定我的所有权限都已设置,并且视图本身没有限制。这是怎么回事?
这是一个大问题,因为我不知道如何检索字段。这是两个视图结果的转储。请注意,node_data_field_game_date_field_game_home_score_value != node_data_field_game_official_field_game_home_score_value。
// View as Admin
stdClass Object
(
[nid] => 3191
[node_data_field_game_date_field_game_date_value] => 2010-03-27T00:00:00
[node_type] => game
[node_vid] => 5039
[node_data_field_game_date_field_game_official_value] => 0
[node_node_data_field_game_home_team_title] => TeamA
[node_node_data_field_game_home_team_nid] => 3396
[node_data_field_game_date_field_game_home_score_value] => 68
[node_node_data_field_game_visitor_team_title] => TeamB
[node_node_data_field_game_visitor_team_nid] => 3442
[node_data_field_game_date_field_game_visitor_score_value] => 118
)
// View as Anonymous
stdClass Object
(
[nid] => 3191
[node_data_field_game_date_field_game_date_value] => 2010-03-27T00:00:00
[node_type] => game
[node_vid] => 5039
[node_data_field_game_official_field_game_official_value] => 0
[node_node_data_field_game_home_team_title] => TeamA
[node_node_data_field_game_home_team_nid] => 3396
[node_data_field_game_official_field_game_home_score_value] => 68
[node_node_data_field_game_visitor_team_title] => TeamB
[node_node_data_field_game_visitor_team_nid] => 3442
[node_data_field_game_official_field_game_visitor_score_value] => 118
)
I'm using views_get_view_result
to directly access the data in a view. I've stumbled upon this odd behavior where cck fields are prefixed with the first field name as a query optimization. Explained here.
What's bizarre though is that fields are named differently depending on whether I retrieve that data as Anonymous or as Admin. I'm pretty sure all my permissions are set up, and the view itself has no restrictions. What is going on here?
This is a big problem since I can't know how to retrieve a field. Here's a dump of the two view results. Notice that node_data_field_game_date_field_game_home_score_value != node_data_field_game_official_field_game_home_score_value.
// View as Admin
stdClass Object
(
[nid] => 3191
[node_data_field_game_date_field_game_date_value] => 2010-03-27T00:00:00
[node_type] => game
[node_vid] => 5039
[node_data_field_game_date_field_game_official_value] => 0
[node_node_data_field_game_home_team_title] => TeamA
[node_node_data_field_game_home_team_nid] => 3396
[node_data_field_game_date_field_game_home_score_value] => 68
[node_node_data_field_game_visitor_team_title] => TeamB
[node_node_data_field_game_visitor_team_nid] => 3442
[node_data_field_game_date_field_game_visitor_score_value] => 118
)
// View as Anonymous
stdClass Object
(
[nid] => 3191
[node_data_field_game_date_field_game_date_value] => 2010-03-27T00:00:00
[node_type] => game
[node_vid] => 5039
[node_data_field_game_official_field_game_official_value] => 0
[node_node_data_field_game_home_team_title] => TeamA
[node_node_data_field_game_home_team_nid] => 3396
[node_data_field_game_official_field_game_home_score_value] => 68
[node_node_data_field_game_visitor_team_title] => TeamB
[node_node_data_field_game_visitor_team_nid] => 3442
[node_data_field_game_official_field_game_visitor_score_value] => 118
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常奇怪的行为。也许是内容许可的问题?
Very weird behavior. Maybe it's a problem with content permission?