2017-10-25 9 views
3

Symfony Table은 일반적으로 첫 번째 행을 다른 행과 다르게 표시합니다. 그러나 첫 번째 행과 첫 번째 행에 동일한 스타일을 사용하고 싶습니다. 나는 TableStyle이 존재한다는 것을 알고 있지만 첫 번째 열에 첫 번째 행에 동일한 스타일을 지정하는 방법을 알 수 없습니다. 이 예제에서는 표 1에서 첫 번째 열이 녹색 (텍스트 행 A, 행 B 및 행 C)으로 표시되기를 원합니다.Symfony Table의 첫 번째 열을 첫 번째 행과 동일한 방식으로 포맷하는 방법은 무엇입니까?

$table = new Table($output); 
$table 
    ->setHeaders(array('Col A', 'Col B', 'Col C')) 
    ->setRows(array(
     array('Row A', 'Divine Comedy', 'Dante Alighieri'), 
     array('Row B', 'A Tale of Two Cities', 'Charles Dickens'), 
     array('Row C', 'The Lord of the Rings', 'J. R. R. Tolkien'), 
    )) 
; 
$table->render(); 

examplee

건배 당신은 TableStyle 인스턴스를 생성해야이 같은 cellRowContentFormat 설정

답변

2

:

<?php 

use Symfony\Component\Console\Helper\Table; 

require_once 'vendor/autoload.php'; 

$output = new Symfony\Component\Console\Output\ConsoleOutput(); 
$table = new Table($output); 
$style = new \Symfony\Component\Console\Helper\TableStyle(); 
$style->setCellRowContentFormat('<info> %s </info>'); 
$table->setColumnStyle(0, $style); 
$table 
    ->setHeaders(array('Col A', 'Col B', 'Col C')) 
    ->setRows(array(
     array('Row A', 'Divine Comedy', 'Dante Alighieri'), 
     array('Row B', 'A Tale of Two Cities', 'Charles Dickens'), 
     array('Row C', 'The Lord of the Rings', 'J. R. R. Tolkien'), 
    )) 
; 
$table->render(); 

이 예제 표는 다음과 같은 코드를 사용하여 생성 할 수 있습니다

TableStyle::$cellRowContentFormatTableStyle::$cellHeaderFormat 구성원 기본값을 참조하십시오. 기본적으로 $cellHeaderFormat'<info>%s</info>'이며이 값은 셀 머리글을 녹색 (정보 색)으로 만듭니다.