Drupal进度条

Drupal有一个内置的百分比进度条显示操作进度的工具batch.

使用方式如下:

batch_set(batch_example_batch_1());

batch_process(
'redirect_page.php');

function batch_example_batch_1() {

    
for ($i = 0$i<100$i++) {
        
$operations[] = array('batch_example_op_1', array($nid));
    }
    
$batch = array(
            
'operations' => $operations,
            
'finished' => 'batch_example_finished',
    );
    
return $batch;
}

function batch_example_op_1($nid, &$context) {

    do_something();

    
// Store some result for post-processing in the finished callback.
    $context['results'][] = "do something";

    
// Optional message displayed under the progressbar.
    $context['message'= t('Loading @title', array('@title' => $node->title));

}

function batch_example_finished($success, $results, $operations) {
    
if ($success) {
        
$message = count($results. ' processed.';
    }
    
else {
        
$error_operation = reset($operations);
        
$message = 'An error occurred while processing ' . $error_operation[0. ' with arguments :' . print_r($error_operation[0], TRUE);
    }
    drupal_set_message(
$message);


posted @ 2011-07-05 09:49  猫之良品  阅读(567)  评论(0编辑  收藏  举报