web-dev-qa-db-ja.com

なぜ出力できないのですか?

stdClass Object(
  [nid] => 98
  .......
  [title] => hello world!
  [body] =>
  ........
  [field_img] => Array(
    [0] => Array(
      [fid] => 200
      [list] => 1
      [data] => Array(
        [alt] => 
        [title] => 
      )

      [uid] => 1
      [filename] => coupon.jpg
      [filepath] => sites/default/files/coupon_0.jpg
      [filemime] => image/jpeg
      [filesize] => 4434
      [status] => 1
      [timestamp] => 1302080050
      [nid] => 98
      [view] =>  **the image**
      ......
    )
  )
)

オブジェクトが$testであるとすると、echo $test->field_img[0]["timestamp"]views-view-fields.tpl.php1302080050を出力しますが、echo $test->field_img[0]["nid"]echo $test->field_img[0]["view"]は何も出力しません。 98と画像が印刷できません。 print_r($test->field_img[0])はノードIDとviewを出力しませんか?どうして?

1
enjoylife

ビューテンプレートファイルでは、次のオブジェクトにアクセスできます。

  • $row
  • $fields['field_my_field_value']->row
  • $fields['field_my_file_value']->content

あなたの場合、複数の画像オブジェクトにアクセスすることはできません。各アイテムのデータを取得するには、外部関数を呼び出す必要があります。

$arg = (object) array(
  'type' => $fields['type']->raw,
  'vid' => $fields['vid']->raw,
);
$files = filefield_get_node_files($arg);

foreach ($files as $file) {
  print theme('imagecache', 'preview_body', $file['filepath']);
}
3
dobeerman