-1
我想生成包含在Drupal 7 由另一模塊文件生成圖像的實體這是我的代碼:創建實體的對Drupal的像場7
global $user;
$apercu = $_SESSION['image_generate'];
$file_apercu = new StdClass();
$file_apercu->uid = $user->uid;
$file_apercu->uri = $apercu;
$file_apercu->filemime = file_get_mimetype($file_apercu->uri);
$file_apercu->status = 1;
$file_apercu = file_save($file_apercu);
$file_apercu = (array) $file_apercu;
$file_apercu = array($file_apercu);
$pdf = $_SESSION['pdf']->uri;
$file_pdf = new StdClass();
$file_pdf->uid = $user->uid;
$file_pdf->uri = $pdf;
$file_pdf->filemime = file_get_mimetype($file_pdf->uri);
$file_pdf->status = 1;
$file_pdf = file_save($file_pdf);
$file_pdf = (array) $file_pdf;
$file_pdf = array($file_pdf);
$form_panier = $_SESSION['form_state_panier'];
$sql = db_query('SELECT MAX("order_id")
FROM commerce_order
WHERE uid = '.$user->uid.'')->fetchAssoc();
$values = array(
'type' => 'commandeflyer',
'uid' => intval($user->uid),
'status' => 1,
'comment' => 0,
'promote' => 0,
);
$entity = entity_create('node', $values);
$ewrapper = entity_metadata_wrapper('node', $entity);
$ewrapper->title->set('commandeflyer'.$sql['MAX("order_id")']);
$ewrapper->field_flyer_image_commande->set($file_apercu);
$ewrapper->field_pdf->set($file_pdf);
$ewrapper->field_numcommande->set(intval($sql['MAX("order_id")']));
$ewrapper->save(true);
entity_save('node', $entity);
當我運行這段代碼我得到這個錯誤:
EntityMetadataWrapperException : Invalid data value given. Be sure it matches the required data type and format. dans EntityMetadataWrapper->set() (ligne 122 dans /var/www/commerce_kickstart-7.x-2.9/profiles/commerce_kickstart/modules/contrib/entity/includes/entity.wrapper.inc).
但我的類型相應:PDF爲PDF和JPG爲圖像。 謝謝你的幫助。