Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Symfony控制台中添加跨多行的行_Php_Symfony_Console_Command Line Interface - Fatal编程技术网

Php 在Symfony控制台中添加跨多行的行

Php 在Symfony控制台中添加跨多行的行,php,symfony,console,command-line-interface,Php,Symfony,Console,Command Line Interface,我目前正在使用Symfony控制台开发CLI,在添加跨多行的行时遇到了一个问题 我的代码是 $table = new Table($output); $table->setHeaders(['Elements','Properties']); foreach($elements as $key => $element) { if ($key != 'templates') { //process element $rowcount = 0; fore

我目前正在使用Symfony控制台开发CLI,在添加跨多行的行时遇到了一个问题

我的代码是

$table = new Table($output);
$table->setHeaders(['Elements','Properties']);

foreach($elements as $key => $element) {  
  if ($key != 'templates') {
    //process element
    $rowcount = 0;
    foreach($element as $name => $component){

      if(is_string($component)){

        $strings[] = $name.' = '.($component == '' ? 'empty' : $component);
        $rowcount++;
      }
    }

    //creating row
    $count = 0;
    foreach ($strings as $string) {
      if ($count == 0) {
        $frow[] = new TableCell($key, ['rowspan' => $rowcount]);
        $frow[] = $string;
      } else {
        $row[] = $string;
      }    

      $count++;
    }

    $rows = [$frow,$row];   
    var_dump($rows);
    $table->addRows($rows);
    unset($frow,$row,$strings);
  }
}        

$table->setStyle('borderless');
$table->render();
此时的
var\u dump
将创建此结果

array(2) {
      [0]=>
      array(2) {
        [0]=>
        object(Symfony\Component\Console\Helper\TableCell)#63 (2) {
          ["value":"Symfony\Component\Console\Helper\TableCell":private]=>
          string(5) "forms"
          ["options":"Symfony\Component\Console\Helper\TableCell":private]=>
          array(2) {
            ["rowspan"]=>
            int(4)
            ["colspan"]=>
            int(1)
          }
        }
        [1]=>
        string(12) "name = forms"
      }
      [1]=>
      array(3) {
        [0]=>
        string(18) "path = admin/forms"
        [1]=>
        string(14) "scope = system"
        [2]=>
        string(16) "attachto = empty"
      }
    }
CLI应该如下所示

============= ===================
Elements      Properties
============= ===================
forms          name = forms
               path = admin/forms
               scope = system
               attachto = empty
我不知道这是否太多,但问题是第二列的对齐方式完全脱节。scope=system部分移到第三列