我正在学习批处理操作api。我试图使用表单创建一个批处理操作这里是我的hook_form
function batch_form_get_form($form, &$form_state){
$form = array();
$form['select'] = array(
'#title' => 'Select',
'#type' =>'select',
'#options' => array(
'batch1' => 'Batch 1',
'batch2' => 'Batch 2',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit'
);
return $form;
}
这是我的表单提交功能
function batch_form_get_form_submit($form,&$form_state){
$function = 'batch_process_form';
$_SESSION['http_request_count'] =0;
$batch = $function;
batch_set($batch);
dsm ($function);
}
这是我在batch_set函数
上使用的批处理函数function batch_process_form(){
for($i=0; $i<10; $i++){
$operations[] = array('batch_operation_result',array($i));
}
$title = "Batch Started";
$init_message = "Initialing Batch";
$progress_message = "Work in Progress";
$batch = array(
'operations' => $operations,
'title' => $title,
'init_message' => $init_message,
'progress_message' => $progress_message,
);
return $batch;
}
当我尝试运行批处理时出现以下错误
Fatal error: Unsupported operand types in /home/dina/static/d7/includes/form.inc on line 4396
在form.inc
的第4396行 $batch_set = $init + $batch_definition + $defaults;
我不知道我错过了什么
答案 0 :(得分:1)
我认为你错过了一件事。
在提交功能中,而不是
$ batch = $ function;
尝试
$ batch = $ function();
祝你好运