>  기사  >  백엔드 개발  >  How to store node content in Drupal_PHP教程

How to store node content in Drupal_PHP教程

WBOY
WBOY원래의
2016-07-14 10:07:181020검색

You will be surprised when you look at the node table in Drupal. That is because you can not find the content field which is used to store the content. In fact, Drupal uses field API to store the content. Frankly speaking, this is a good design and one of Drupal's advantage. You can understand node as the base table and it can be extended in other tables.

In the following, i will use Blog module to make in-depth explanation.

1. Declare blog node type

[html] 
function blog_node_info() { 
  return array( 
    'blog' => array( 
      'name' => t('Blog entry'), 
      'base' => 'blog', 
      'description' => t('Use for multi-user blogs. Every user gets a personal blog.'), 
    ) 
  ); 

From Node API, we can know that hook_node_info is to define module-provided node types.The base key-value entry in the array means that it will use blog prefix hook at first priority for the node operation callback.
2. Attach the body field to blog node type

[html] 
function blog_install() { 
  // Ensure the blog node type is available. 
  node_types_rebuild(); 
  $types = node_type_get_types(); 
  node_add_body_field($types['blog']); 

node_types_rebuild method's task is to collect the data from the modules which implements hook_node_info, then save the data into table node_type and put the data into cache for instant usage.
For function node_add_body_field, it is necessary to look its function body.

[html] 
function node_add_body_field($type, $label = 'Body') { 
   // Add or remove the body field, as needed. 
  $field = field_info_field('body'); 
  $instance = field_info_instance('node', 'body', $type->type);   
  return $instance; 

From the code statements, they are apparently self-explaining. It loads the field body's information and create an instance, then attach the instance to blog node type. I will explore field API and Node type UI (filed and node rendering) next time to make it as complete story.

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477882.htmlTechArticleYou will be surprised when you look at the node table in Drupal. That is because you can not find the content field which is used to store the content. In fact, Drupal uses field A...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.