欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal 7 有连续编号的字段模块吗

shiping1 的头像
大家好

我想给新的内容类型设置一个字段,字段为数字编号,自动的,比如从1开始,如果建立一个新内容(node)时此字段就会自动增加为 2,3,4......

https://drupal.org/project/serial


 

我需要一场自动编码我的内容类型,但从某个值如2000。我试着连续场和计算字段。也` T明白怎么做。数(使用串行现场)并自动递增,但我不能定义一个起始数。

反正是要这样做吗?

谢谢!

我需要一场自动编码我的内容类型,但从某个值如2000。我试着连续场和计算字段。也` T明白怎么做。数(使用串行现场)并自动递增,但我不能定义一个起始数。

反正是要这样做吗?

谢谢!
答案1

You can do this by using Computed Field. Add a computed field to your content type and set the data type to be integer. In the Computed Field (PHP) textarea this code will work for you:

if (empty($entity_field[0]['value'])) {
  $count = db_select('node')->fields('node')->condition('type', $entity->type)->execute()->rowCount();
  $entity_field[0]['value'] = $count + 2000;
}

 

This checks if a value for this field is already set for this node and if not - it gets the total number of nodes of this content type, adds a constant (2000 in this example) and sets the result as the value for your field.

答案1译文

您可以通过使用计算字段。添加计算字段到你的内容类型和设置的数据类型是。在计算字段(PHP)文本代码将为你工作:

if (empty($entity_field[0]['value'])) {
  $count = db_select('node')->fields('node')->condition('type', $entity->type)->execute()->rowCount();
  $entity_field[0]['value'] = $count + 2000;
}

这一检查,如果该域的值已被设置为该节点,如果没有得到这个内容类型的节点数,增加了一个常数(在这个例子中的2000)和集的结果作为你的字段值。

答案2

The Serial Module generates a table whose name isserial_bundlename_fieldname i.e. If you have added a field name 'field_job_id' for bundle 'Jobs' then a table 'serial_jobs_field_job_id' will be created.

The table contains 2 fields 'sid' and 'nid' 'sid' is auto increment field.

You can use a tool like phpMyAdmin and execute the following query

ALTER TABLE serial_jobs_field_job_idAUTO_INCREMENT =2000;

This should possibly set the starting value for autoincrement field.

答案2译文

串行模块生成一个表的名字serial_bundlename_fieldname即如果你添加了一个字段名称”field_job_id“束”工作然后一个表serial_jobs_field_job_id“将被创建。

该表包含2域”希德'和'NID“”希德是自动递增字段。

你可以使用phpMyAdmin工具执行以下查询

修改表serial_jobs_field_job_idauto_increment = 2000;

这应该可能设置为递增字段的起始值。

答案3
 

We use custom auto-numbers on several custom recordtypes in our Drupal 6 system (the following should also work for Drupal 7). To make it work, we implemented a rule using the Rules module that fires upon saving the record.

The rule runs ON event After saving content and should verify that you're saving the content type you're interested in. (For example, if you're auto numbering Widgets, add an IF for Content type is Widget.

For your actions, put an *Populate created content's 'custom_number' field* action on the rule (where 'custom_number' is your auto-number field), and follow this example:

$number = db_result(db_query(
    "SELECT MAX(field_custom_number_value) FROM {content_type_widget}"));

if(empty($number) || $number < 200) { // Replace 200 with your starting value
    $number = 200;
} else {
    $number++;
}

return array( 0 => array('value' => $number) );

Every time you save a new widget, the system runs a query to find the max custom_number already assigned. If none are assigned, or a number less than 200 is assigned, the system will assign 200; otherwise, it will assign 1 more than the current max number assigned.

If you wanted to, you could also add a line of debug code to add a watchdog line or other debug event in the event that a number less than your desired minimum is discovered.

答案3译文

我们使用定制的汽车数量在Drupal 6系统的几个自定义的记录类型(以下也应该为Drupal 7工作)。使它工作,我们实现了一个规则,利用规则模块,火灾对保存记录。

规则运行事件保存后的内容要确认你节省你感兴趣的内容类型。(例如,如果你添加一个自动编号的部件,如内容类型是部件

你的行动,把一个填充创建内容的custom_number”领域的行动的规则(如“custom_number‘你的汽车号码字段),并按照这个例子:

$number = db_result(db_query(
    "SELECT MAX(field_custom_number_value) FROM {content_type_widget}"));

if(empty($number) || $number < 200) { // Replace 200 with your starting value
    $number = 200;
} else {
    $number++;
}

return array( 0 => array('value' => $number) );

每一次你保存一个新的部件,该系统运行一个查询来找到最大custom_number已经分配。如果没有指定,或一个数小于200的分配,系统会分配200;否则,它将分配1比目前的最大编号。

如果你想,你也可以添加一行代码的调试事件中,一个数小于所需的最小被发现增加一个看门狗线或其他调试事件。

来自  http://www.4byte.cn/question/668358/drupal-auto-number-field-for-content-type-with-starting-value.html

普通分类: