我正在尝试将文件字段从节点复制到另一个节点,当我谷歌如何操作时,我找到了这个解决方案
$fid=9;//fid of the file
$file = file_load($fid);
$node->field_pro_thumbnail[LANGUAGE_NONE][] = array($file);
node_save($node);
然而我收到以下错误
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null: INSERT INTO {file_usage} (fid, module, type, id, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => file [:db_insert_placeholder_2] => node [:db_insert_placeholder_3] => 51 [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 692 of C:\xampp\htdocs\someueue\includes\file.inc)."
任何帮助吗??
答案 0 :(得分:-1)
可能是这样的:
$node->field_pro_thumbnail[LANGUAGE_NONE][$fid] = array($file);
答案 1 :(得分:-1)
答案是
$node->field_pro_thumbnail[LANGUAGE_NONE][$fid] = (array)$file;