2017-08-10 77 views
0

我发现了一篇文章,展示了如何将shell输出和错误重定向到CakePHP 2.x的文件,关于如何使用CakePHP 3.x做到这一点的任何想法?收集CakePHP 3 Shell输出和错误

这里是代码片段我发现CakePHP的2.x的

public function __construct($stdout = null, $stderr = null, $stdin = null) { 
    // This will cause all Shell outputs, eg. from $this->out(), to be written to 
    // TMP.'shell.out' 
    $stdout = new ConsoleOutput('file://'.TMP.'shell.out'); 

    // You can do the same for stderr too if you wish 
    // $stderr = new ConsoleOutput('file://'.TMP.'shell.err'); 

    parent::__construct($stdout, $stderr, $stdin); 
} 

但我收到以下错误

PHP Fatal error: Class 'App\Shell\ConsoleOutput' not found 

是ConsoleOutput CakePHP中3.X如果是这样,是什么命名空间?

回答

1

您需要使用下面像类:

use Cake\Console\ConsoleIo; 
use Cake\Console\ConsoleOutput; 

$output = new ConsoleOutput(); 
$io = new ConsoleIo($output); 
+0

这并不似乎输出虽然重定向到一个文件...任何想法,为什么? –

+0

链接:https://stackoverflow.com/a/11606218/5737771 –

+0

雅,我试过,它不工作...我发布了一个新的问题... https://stackoverflow.com/questions/45620364/cakephp -3-重定向-consoleoutput到文件 –