2011-05-14 106 views
1

所有人。我有一个问题与视图2.我有一个行的风格设置为字段(只有标题字段)的视图。我想用逗号分隔列表显示这些标题。 例如:逗号分隔视图列表

哈萨克斯坦,英格兰,中国,韩国

试着这样做:

foreach($fields['title']->content as $titles) { 

$zagolovki[] = $titles['view']; 

} 

$title_list = implode(', ', $zagolovki); 

print $title_list; 

但它没有工作 - 在争论说错误。请帮助我某人在逗号分隔列表的视图中显示节点标题。谢谢!

+0

你能发表更多的代码吗?这是来自模板吗?我会说'$ fields ['title'] - > content'不是一个数组。 – nonsenz 2011-05-14 21:14:20

+0

这就是我的views-view-fields-related-posts-by-author-block-1.tpl.php模板中的所有代码。我用这种方式显示字段。 – heihachi88 2011-05-15 02:48:48

回答

0

它说错误发生在哪里? nonsenz可能是正确的,$fields['title']->content不是一个数组。仅用于调试,请尝试添加

print("array content: "+ is_array($fields['title']->content)); 

之前的foreach。如果你知道$领域是一个小的嵌套结构,你可以尝试

print(str_replace("\n","<br/>",print_r($fields,true)); 

,看看究竟是什么在里面,这样就可以使验证你要遍历是什么,其实迭代。

1

我quikly参加了自带的意见模块views-view-fields.tpl.php看看它说

/* 
* - $view: The view in use. 
* - $fields: an array of $field objects. Each one contains: 
* - $field->content: The output of the field. 
* - $field->raw: The raw data for the field, if it exists. This is NOT output safe. 
* - $field->class: The safe class id to use. 
* - $field->handler: The Views field handler object controlling this field. Do not use 
*  var_export to dump this object, as it can't handle the recursion. 
* - $field->inline: Whether or not the field should be inline. 
* - $field->inline_html: either div or span based on the above flag. 
* - $field->separator: an optional separator that may appear before a field. 
* - $row: The raw result object from the query, with all data it fetched. 
*/ 

所以我觉得$领域是你应该遍历什么。如果您想调试您的$fields的结构,请安装devel-module并使用dpm()dsm()来显示$field的内容。也许可以使用您编辑的模板(应该是views/theme文件夹中的view-module模板之一),然后看看会发生什么。