2011-05-14 105 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模板之一),然後看看會發生什麼。