【发布时间】:2011-02-09 20:34:27
【问题描述】:
我正在为我的组织编写一个模块,用于将静态文件的 XML 提要缓存到我们网络服务器上的任意位置。我是 Drupal 开发的新手,想知道我是否以正确的方式处理这个问题。
基本上我:
- 通过菜单挂钩公开一个 url,用户可以在其中进入网络服务器上的输出目录并按下“转储”按钮,然后让 PHP 转到 drupal 并获取提要 xml。我不需要有关该功能的帮助,因为我实际上有一个在 Python 中工作的原型(在 Drupal 之外)..
- 使用表单参数为表单提供回调,我可以在其中执行我的逻辑。
这里是菜单钩子:
function ncbi_cache_files_menu() {
$items = array();
$items['admin/content/ncbi_cache_files'] = array(
'title' => 'NCBI Cache File Module',
'description' => 'Cache Guide static content to files',
'page callback' => 'drupal_get_form',
'page arguments' => array( 'ncbi_cache_files_show_submit'),
'access arguments' => array( 'administer site configuration' ),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
我在以下位置生成表单:
function ncbi_cache_files_show_submit() {
$DEFAULT_OUT = 'http://myorg/foo';
$form[ 'ncbi_cache_files' ] = array(
'#type' => 'textfield',
'#title' => t('Output Directory'),
'#description' => t('Where you want the static files to be dumped.
This should be a directory that www has write access to, and
should be accessible from the foo server'),
'#default_value' => t( $DEFAULT_OUT ),
'#size' => strlen( $DEFAULT_OUT ) + 5,
);
$form['dump'] = array(
'#type' => 'submit',
'#value' => 'Dump',
'#submit' => array( 'ncbi_cache_files_dump'),
);
return system_settings_form( $form );
}
那么功能就在回调中:
function ncbi_cache_files_dump( $p, $q) {
//dpm( get_defined_vars() );
$outdir = $p['ncbi_cache_files']['#post']['ncbi_cache_files'];
drupal_set_message('outdir: ' . $outdir );
}
问题:这是在 Drupal 中处理任意表单的一种不错的方式吗?我真的不需要监听任何 drupal 钩子,因为我基本上只是在做一些 URL 和文件处理。
我在回调 ($q) 中得到的那些参数是什么?那是我猜的表单数组,带有帖子值?这是获取表单参数的最佳方式吗?
感谢您的建议。
【问题讨论】: