tableselect drupal 7中的空记录

时间:2013-03-08 08:29:57

标签: php drupal

我正在创建一个类似于drupal 7中的users表的tableselect。我在屏幕上显示空消息“没有可用的插件”。即使记录是在数组中获取的。这是我的代码

function massignite_menu() {
$items = array();
$items['massig/manage'] = array(
'page callback' => 'massignite_selector',
'file' => 'manage.inc',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}

function massignite_selector() {
include('massrpc.php');
$header = array(
'plugin' => t('Plugin'),
'status' => t('Status'),
);

$params = array(
'username' => "foo",
'password' => "bar",
);
$pluginsRecords = xmlGetPlugins($params);
foreach ($pluginsRecords as $key=>$plugin) {
 $options[$key] = array(
  'plugin' => $plugin['Name'],
  'status' =>  $plugin['is_active']?'Activated':'Deactivated',
);
}
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No plugins available.'),
'#multiple' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Activate'),
);
$form['pager'] = array('#markup' => theme('pager'));
return $form;

}

我按照here给出的教程。任何帮助将是apreciated

编辑: - 解决了!!显然,我错误地通过menu_hook调用了我的函数。正确的做法就是这样。

function massignite_menu() {
$items = array();
$items['massig/manage'] = array(
'title' => 'Plugins',
'page callback' => 'drupal_get_form',                             
'page arguments' => array('massignite_table_form'),
'file' => 'manage.inc',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);

1 个答案:

答案 0 :(得分:0)

您需要使用hook_formID_form,

在自定义模块中创建一个真实的表单

请参阅此tutorial