我希望开发字段添加到用户配置文件在Drupal 7,如电话号码和CV模块...我不知道怎么说(使用数据库或使用领域API)请帮我做。
任何明确的教程将不胜感激。
Answer 1:
尝试按照下面的代码
$myField_name = "NEW_FIELD_NAME";
if(!field_info_field($myField_name)) // check if the field already exists.
{
$field = array(
'field_name' => $myField_name,
'type' => 'text',
);
field_create_field($field);
$field_instance = array(
'field_name' => $myField_name,
'entity_type' => 'user', // change this to 'node' to add attach the field to a node
'bundle' => 'user', // if chosen 'node', type here the machine name of the content type. e.g. 'page'
'label' => t('Field Label'),
'description' => t(''),
'widget' => array(
'type' => 'text_textfield',
'weight' => 10,
),
'formatter' => array(
'label' => t('field formatter label'),
'format' => 'text_default'
),
'settings' => array(
)
);
field_create_instance($field_instance);
希望这个作品......穆罕默德。
Answer 2:
您可以使用Profile2的模块: http://drupal.org/project/profile2
文章来源: How to add new fields to user profile in Drupal 7 programmatically