0

我正在使用表格主题。下面是我尝试创建表格以显示行和列中的值的整个代码。该代码还包含我的主题的注册。这些值来自代码中的 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 我不需要复选框,但我使用了此代码,因为我遵循了它从我之前使用的一个例子。

你能否指导我错误在哪里,我得到了这个奇怪的输出。

    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;

      }

谢谢安吉拉

4

1 回答 1

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
于 2011-12-30T03:51:23.583 回答