2011-01-12 136 views

回答

19

标准方法是在安装钩子的查询中执行此操作。

从devel模块:

/** 
* Implementation of hook_install() 
*/ 
function devel_install() { 
    drupal_install_schema('devel'); 

    // New module weights in core: put devel as the very last in the chain. 
    db_query("UPDATE {system} SET weight = 88 WHERE name = 'devel'"); 

    ... 
} 
+1

正确的方式这看起来正确的,但就是调用drupal_install_schema()来设置权重只是需要? – markdorison

+1

你也可以手动设置权重...... drupal_install_schema()调用在那里,因为devel的安装钩子需要安装它的模式。 –

+0

考虑到设置重量并不总是你需要做的。在某些情况下,我遇到了,设置“引导程序”也是必需的,重量较轻但带有“引导程序”的模块在“标准”模块之前加载 - 考虑到这一点... – Shushu

4

如果由于某种原因,你必须坚持它在更新钩,你会想正确地从update_sql返回结果,免得你讨厌看的无害的错误。

function mymodule_update_6000(&$sandbox) { 
    $res[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'mymodule'"); 
    return $res; 
} 
25

这是做在Drupal 7

/** 
* Implements hook_enable() 
*/ 
function YOUR_MODULE_enable() { 
    db_update('system') 
    ->fields(array('weight' => 1)) 
    ->condition('type', 'module') 
    ->condition('name', 'YOUR_MODULE') 
    ->execute(); 
} 
+0

应放置在your_module.install文件中。 – duru