Drupal传递参数到页面

sto*_*tic 9 drupal drupal-7

我有一个自定义Drupal模块在表中显示一些数据.每行都有一个链接,如果单击该链接将删除相关行.具体来说,当点击链接时,它将使用户进入确认页面.这个页面实际上只是一个drupal表单,上面写着"你确定"有两个按钮:'是','不'.我想我需要将rowID传递给确认页面.

我的问题:在Drupal 7中将数据传递到新页面的典型方法是什么?我想我可以将rowID添加到URL并使用确认页面中的$ _GET [] ...我不认为这是非常安全的,并且想知道是否有更好的'Drupal'方式.

谢谢!

red*_*ben 17

你会使用类似下面的东西

<?php
function yourmod_menu() {
  // for examlple
  $items['yourmod/foo/%/delete'] = array(
    'title' => 'Delete a foo',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('youmode_foo_delete_confirm', 2), // 2 is the position of foo_id
    'access arguments' => array('delete foo rows'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function yourmod_foo_delete_confirm($form, &$form_state, $foo_id) {
  // load the row
  $foo = yourmod_get_foo($foo_id);

  // build your form, if you need to add anything to the confirm form
  // ....
  // Then use drupal's confirm form
  return confirm_form($form,
                  t('Are you sure you want to delete the foo %title?',
                  array('%title' => $foo->title)),
                  'path/to/redirect',
                  t('Some description.'),
                  t('Delete'),
                  t('Cancel'));

}

?>
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看核心模块如何执行此操作的示例(请参阅node_delete_confirm)