Drupal 7.x模块开发之node创建

来源:互联网 发布:2017网络贷款诈骗案例 编辑:程序博客网 时间:2024/06/06 01:38

Solutions:

在drupal的模块开发中有时需要手动创建某种类型的node,下面是是实际创建方法:


function node_create(){global $user;//可选项,如需获得用户信息可以使用;$node = (object) NULL;//定义将要创建的node对象,注意是object对象;$node->type = 'node_type';//定义node的类型;$node->uid = $user->uid;//这里用到了上面定义的$user,将node的创建者指定为当前用户;</span>
<span style="font-family:KaiTi_GB2312;font-size:18px;">$node->created = strtotime("now");//指定node的创建时间;$node->changed = strtotime("now");//指定node的最新修改时间;$node->status = 1;//指定node的状态,具体见下面的补充材料;$node->comment = 0;$node->promote = 0;$node->moderate = 0;$node->sticky = 0;$node->language = 'zh-hans';$node->title = t('zh-hans');$node->refresh = FALSE;//----attention please:特别注意这个选项,如果没有设置会有报错;node_save($node);}</span>

补充材料:

     Node 相关属性

nid :node的唯一标识;


vid:A unique revision ID for the node, needed because Drupal can store content revisions for each node.The vid is unique across all nodes and node revisions.


type:Every node has a node type-for example,blog,story,article,image,and so on.


language:The language for the node.Out of the box,this column is empty,indicating language-neutral nodes.


title:A short 255-character string used as the node's title,unless the node type declares that it does not have a title,indicated by a 0 in the has_title field of the node_type table.


uid:The user ID of the author.By default,nodes have a single author.


status:A value of 0 means unpublished;that is ,content is hidden from those who don't have the "administer nodes" permission.A value of 1 means the node is published and the content is visible to those users with the "access content" permission.The display of a published node may be vetoed by Drupal's node-level access control system.A published node will be indexed by the search module if the search module is enabled.


created:A unix timestamp of when the node was created.


changed: A unix timestamp of when the node was last modified.If you're using the node revisions system,the same value is used for the timestamp field in the node_revisions table.


comment:An integer field describing the status of the node's comments,with three possible values:0:Comments have been disabled for the current node;1:No more comments are allowed for the current node.Inthe user interface of the node editing form's "Comment settings" section,this is refered to as "Read only":2:Comments can be viewed,and users can create new comments.


promote:An integer field to determine whether to show the node on the front page,with two values:1:promoted to the front page;0:Node isn't shown.


sticky:when drupal displays a listing of nodes on a page, the default behavior is to list first those nodes marked as sticky,and then list the remaining unsticky nodes in the list by date created. In other words,sticky nodes stick to the top of node listings.A value of 1 means sticky, and a value of 0 means unsticky.


tnid:when a node serves as the translated version of another node,the nid of the source node being translated is stored here.


translate: A value of 1 indicates that the translation needs to be updated; a value of 0 means translation is up to date.




0 0
原创粉丝点击