$ this-> table()抛出[InvalidArgumentException]一行必须是数组或TableSeparator实例

时间:2017-05-22 11:07:10

标签: laravel symfony command-line laravel-4

我已经编写了L4 Command类,但table输出正在抛出异常。

<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class Table extends Command {

    protected $name = 'table';

    public function fire()
    {
        //output table;
        $header = ['Name', 'Email', 'Age'];
        $row = ['Luke', 'me@email.uk', '99'];

        $this->info(sprintf("is array ? %s", is_array($row) ? 'true' : 'false'));
        //outputs is array ? true
        $this->table($header, $row);
        //throws exception
        // [InvalidArgumentException]
        // A row must be an array or a TableSeparator instance.

    }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

您必须传入一组行。每table个定义:

void table(array $headers, array $rows, string $style = 'default')

所以你要么

$row = [['Luke', 'me@email.uk', '99']]; // An array of arrays, containing one row

$this->table($header, [$row]);