使用hooku update在Drupal中更新和设置变量的例程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用hooku update在Drupal中更新和设置变量的例程相关的知识,希望对你有一定的参考价值。
Drupal allows hook_update_N to run any sort of code. Most of the time, however, people only use this to alter the database scheme.But you can use it for much more. Like setting variables, creating nodes, importing views and so on.
This code shows how to set a series of variables in Drupal.
When you deploy this code, running update.php will set all the variables as in the listing.
I typically catch this in a module called 'projectname_meta'. So this function would go in projectname_meta.install, and will be called from projectname_meta_install and projectname_meta_update_5002, for example.
/** * Sets a variable range of variables to LUX-values. * * @return * An array of name=>value pairs containing the var and its value. */ function _projectname_meta_set_variables() { 'site_name' => 'My New Site!', 'site_offline' => FALSE, ); foreach($variables as $key => $value) { variable_set($key, $value); $statii[] = "$key => $value"; } }
以上是关于使用hooku update在Drupal中更新和设置变量的例程的主要内容,如果未能解决你的问题,请参考以下文章
Drupal 6.x中的hooku viewsu postu render