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

标签 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.

    }
}

有什么想法吗?

最佳答案

您必须传入行数组。根据 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]);

关于laravel - $this->table() 抛出 [InvalidArgumentException] 行必须是数组或 TableSeparator 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44111318/

相关文章:

php - Laravel 4 中的 Cron 作业

database - 在 Laravel 4 中创建多态多对多关系

php - Symfony2 表单组件 - 违反 MVC 和 SRP?

node.js - Gulp安装: 'fs: re-evaluating native module sources is not supported' and node-sass errors

command-line - PSFTP:覆盖现有文件

php - 在 Blade 中用星星显示等级的方法。拉拉维尔

php - Laravel5 Ubuntu 仅在 myvirtualdomain/index.php/subsites 时工作

php - 运行时更改字段属性

php - 从 Symfony/Twig 中的覆盖版本访问父模板

c 命令行参数