![](/img/trans.png)
[英]Drupal : Create variable from custom .module to custom .tpl.php
[英]Create a custom node in drupal by PHP
我創建了一個PHP文件,該文件從URL獲取參數並在drupal 7中創建了一個drupal節點。
碼:
include_once './includes/bootstrap.inc';
define('DRUPAL_ROOT', getcwd());
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$node=new stdClass;
$node->title='ABCD';
$node->type='order';
$node->language=LANGUAGE_NONE;
$node->uid=1;
$node->field_name['und'][0]['value']='ABC';
$node->field_contact['und'][0]['value']='1234567890';
$node->field_addr['und'][0]['value']='LMNOPQRST';
$node->field_email['und'][0]['value']='abc@abc.com';
$node->field_orderdetails['und'][0]['value']='fgheghfgjhgfhj';
$node->field_transaddr['und'][0]['value']='hdfghwgfhwgj';
$node->field_outletid['und'][0]['value']='MCK01';
node_save($node);
?>
我是否需要在drupal中指定有關通過PHP創建此節點的信息?
我是drupal的新手,謝謝
您的代碼足以創建節點。 以下是一些微調的更改:
include_once './includes/bootstrap.inc';
define('DRUPAL_ROOT', getcwd());
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$node = new stdClass();
$node->type = 'order';
node_object_prepare($node); // Prepare node object with default values.
$node->title = 'ABCD';
$node->language = LANGUAGE_NONE; // LANGUAGE_NONE is a constant with value "und".
$node->uid = 1;
$node->field_name[LANGUAGE_NONE][0]['value']='ABC';
$node->field_contact[LANGUAGE_NONE][0]['value']='1234567890';
$node->field_addr[LANGUAGE_NONE][0]['value']='LMNOPQRST';
$node->field_email[LANGUAGE_NONE][0]['value']='abc@abc.com';
$node->field_orderdetails[LANGUAGE_NONE][0]['value']='fgheghfgjhgfhj';
$node->field_transaddr[LANGUAGE_NONE][0]['value']='hdfghwgfhwgj';
$node->field_outletid[LANGUAGE_NONE][0]['value']='MCK01';
node_save($node);
您的代碼非常好。 您只需要在特定事件(在菜單上,或任何節點的添加/編輯/刪除事件)上觸發它即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.