2011-12-28 60 views
0

Iam使用表主題。下面看到的是我創建一個表來顯示行和列中的值的完整代碼。該代碼還包含我的主題註冊。值來自代碼中看到的6個數組,即fileId,fileName等。現在使用此代碼,我得到這個輸出http://www.image-share.com/ijpg-1166-290.html。 我的願望輸出必須看起來像這樣http://www.image-share.com/ijpg-1166-289.html。該數組正在填充正確,因爲我打印出來的值成功,在這裏看到http://www.image-share.com/ijpg-1166-288.html我不需要複選框,但我用這個代碼,因爲我從我之前使用的一個例子跟着它。如何主題Drupal 6表以輸出行和列的數組?

你能指導我哪裏錯誤的地方,我得到這個奇怪的輸出。

function freeway_dashboard_details(){ 

$pidobtained = $_GET['project_id'] ; 


    $fileId = array(); 
    $fileName = array(); 
    $srcLang = array(); 
    $targLang = array(); 
    $statusId = array(); 
    $statusDesc = array(); 

    $LoginClient = new SoapClient("https://freeway.demo.company.com/vojo/FreewayAuth.asmx?wsdl", array("trace"=>1)); 
    $ServicesLink = new SoapClient("https://freeway.demo.company.com/vojo/Service.asmx?wsdl", array("trace"=>1)); 

     try 
     { 
      $arrResponse = $LoginClient->Logon(array ('Username'=>'','Password'=>'')); 
      $ticket = ($arrResponse->LogonResult); 
      $fileStatus = $ServicesLink->GetFileStatus(array('Ticket'=>$ticket,'ProjectID'=>$pidobtained,'SourceLanguageID'=> "", 'TargetLanguageID'=> "",'FileID'=> "",'Filename'=>"")); 
      $arrayPid = array(); 

      foreach($fileStatus->GetFileStatusResult->FileStatuses->FileStatus as $fileStatusObtained) 
      { 
       $arrayPid = get_object_vars($fileStatusObtained); 
       //print_r($fileStatusObtained->FileID);     
       $fileId [] = $fileStatusObtained->FileID; 
       $fileName[] = $fileStatusObtained->Filename; 
       $srcLang[] = $fileStatusObtained->SourceLanguageID; 
       $targLang[] = $fileStatusObtained->TargetLanguageID; 
       $statusId[] = $fileStatusObtained->StatusID; 
       $statusDesc[] = $fileStatusObtained->StatusDescription; 
      } 





      for($n=0;$n <count($fileId);$n+=1){ 
      $options[$fileId[$n]] = ''; 
      $form[$fileId[$n]]['FileID'] = array('#value' => $fileId[$n]); 
      $form[$fileName[$n]]['FileName'] = array('#value' => $fileName[$n]); 
      $form[$srcLang[$n]]['SrcLang'] = array('#value' => $srcLang[$n]); 
      $form[$targLang[$n]]['TarLang'] = array('#value' => $targLang[$n]); 
      $form[$statusId[$n]]['StatusID'] = array('#value' => $statusId[$n]);  
      $form[$statusDesc[$n]]['StatusDesc'] = array('#value' => $statusDesc[$n]);     
      } 

     } 

     catch(SoapFault $exception) 
     {     
      return $exception; 

     } 


     $form['featured'] = array(
     '#type' => 'checkboxes', 
     '#options' => $options, 
     '#multiple' => false, 
     ); 

    return $form; 


} 



    function freeway_theme() { 
return array('freeway_dashboard' => array('arguments' => array('form' => NULL),),'freeway_dashboard_details' => array('arguments' => array('form' => NULL),),); 
    } 



    function theme_freeway_dashboard_details($form) { 
      $rows = array(); 
      foreach (element_children($form) as $key) { 
      $row = array(); 
        if (isset($form[$key]['FileID'])) { 
        $status = drupal_render($form['featured'][$key]); 
        $row[] = array('data' => $status, 'class' => 'checkbox'); 
        $row[] = ''. drupal_render($form[$key]['FileID']) .''; 
        $row[] = array('data' => drupal_render($form[$key]['FileName'])); 
        $row[] = array('data' => drupal_render($form[$key]['SrcLang'])); 
        $row[] = array('data' => drupal_render($form[$key]['TarLang'])); 
        $row[] = array('data' => drupal_render($form[$key]['StatusID'])); 




        $rows[] = $row; 

        } 

      } 
      $header = array(); 
      $header[] = array('data' => t('Featured'), 'class' => 'checkbox'); 
      $header[] = t('File ID'); 
      $header[] = t('File Name'); 
      $header[] = t('Source Language'); 
      $header[] = t('Target Language'); 
      $header[] = t('Status ID'); 
      $header[] = t('Status Description'); 


      $output = theme('table', $header, $rows,array('size'=>10, 'class' => 'table_class')); 
      $output .= drupal_render($form); 


     return $output; 

     } 

感謝 安吉拉

回答

0

裏面還有幾個問題,我認爲,主要是你的形式鍵分配不一致所以一些元素實際上覆蓋現有的,以及一些沒有被發現在你的循環中,並作爲普通形式的項目在表格後輸出。您的代碼可能會短些爲好,試試這個:

freeway_dashboard_details()

$form['#table_values'] = array(); 
$options = array(); 
foreach ($fileStatus->GetFileStatusResult->FileStatuses->FileStatus as $fileStatusObtained) { 
    $form['#table_values'][$fileStatusObtained->FileID] = array(
    'fileId' => $fileStatusObtained->FileID, 
    'fileName' => $fileStatusObtained->Filename, 
    'srcLang' => $fileStatusObtained->SourceLanguageID, 
    'targLang' => $fileStatusObtained->TargetLanguageID, 
    'statusId' => $fileStatusObtained->StatusID, 
    'statusDesc' => $fileStatusObtained->StatusDescription 
    ); 

    $options[$fileStatusObtained->FileID] = ''; 
} 

$form['featured'] = array(
    '#type' => 'checkboxes', 
    '#options' => $options, 
    '#multiple' => false, 
); 

而且在freeway_theme()

$rows = array(); 
foreach (element_children($form['featured']) as $key) { 
    $row = array(); 
    if (isset($form['#table_values'][$key])) { 
    $status = drupal_render($form['featured'][$key]); 
    $row[] = array('data' => $status, 'class' => 'checkbox'); 
    $row[] = array('data' => $form['#table_values'][$key]['fileId']); 
    $row[] = array('data' => $form['#table_values'][$key]['fileName']); 
    $row[] = array('data' => $form['#table_values'][$key]['srcLang']); 
    $row[] = array('data' => $form['#table_values'][$key]['targLang']); 
    $row[] = array('data' => $form['#table_values'][$key]['statusId']); 
    $row[] = array('data' => $form['#table_values'][$key]['statusDesc']); 

    $rows[] = $row; 
    } 
} 

// Rest of the code as it was