English 中文(简体)
Drupal CCK字段选择选项名称,它们在哪里?
原标题:Drupal CCK field select option names, where are they?

我有一个自定义的内容类型,它有一个名为“位置”的字段,这是一个长的选择列表(大约100个项目)。我想得到一个所有位置的数组,这些位置有一段与它们相关联的内容。该字段的数值存储在content_type_[my_content_type]中,但我在存储值名称的数据库中找不到任何位置。我希望这不会太令人困惑——只是想明确一点,我想做这样的事情:

SELECT DISTINCT(field_location_value) FROM content_type_[my_content_type]

然后

SELECT field_location_name_or_something FROM where_on_earth_are_the_names_stored

然后 do something with the two arrays to find the names I want.

有人能帮忙吗?

非常感谢。顺便说一句,Drupal 6。

最佳回答

If you mean select list field of CCK:
Get all location associated with current node (piece of content?):

$node = node_load( YOUR content ID );
print_r($node->field_location); // $node->field_location - this will array of values.

获取该字段的所有值(在“允许的值”中定义):

  $content_field = content_fields( field_location );
  $allowed_values = content_allowed_values($content_field); // array of values
问题回答

经过多次尝试和磨难,我在数据库表content_node_field_instance的字段的widgetsettings字段下发现了这一点。

This Drupal 6 code snipped will retrieve your cck field value options and put them in the $allowed_values variable as an array. Replace YOUR_CCK_FIELD_NAME with your cck field name (name, not label)
$cck_field_name = YOUR_CCK_FIELD_NAME ;
$cck_field = db_fetch_object(db_query("SELECT global_settings FROM {content_node_field} WHERE field_name = %s ", $cck_field_name));
$cck_field_global_settings = unserialize($cck_field->global_settings);
$allowed_values = explode(" ", trim($cck_field_global_settings[ allowed_values ], " "));

在Drupal7中,如果你有一个List(text)类型的字段,那么我已经编写了以下函数来返回一个选项数组:

function get_drupal_select_options($field_name) {
    $options = unserialize(db_query("SELECT c.data
                FROM field_config_instance i
                INNER JOIN field_config c ON c.id = i.field_id
                WHERE i.field_name = :fieldname", array( :fieldname =>$field_name))->fetchField());
    return $options[ settings ][ allowed_values ];
}




相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签