2017-08-10 79 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到文件 –