Answer the question
In order to leave comments, you need to log in
Yii2 advanced console. How is rerutn returned?
Good
Installed YII2 Advanced > php init > 0 > yes .. in general, everything is at a minimum
Create - console/controllers/MakefileController.php
<?php
namespace console\controllers;
use yii\console\Controller;
Class MakefileController extends Controller{
public function actionIndex(){
$fp = fopen("./file.txt", "w");
fwrite($fp, 'qweasdzxc123');
fclose($fp);
return 1234;
}
}
Answer the question
In order to leave comments, you need to log in
Good afternoon. If you want to output something to the console, you need to write data to the output stream. In yii 2, the stdout method is provided for this. Usage example:
private function log($success, $error = null)
{
if ($success) {
$this->stdout(date("Y-m-d H:i:s") . ': Success!', Console::FG_GREEN, Console::BOLD);
} else {
$this->stdout(date("Y-m-d H:i:s") . ': ' . $error, Console::FG_RED, Console::BOLD);
}
echo PHP_EOL;
}
In console controllers, return on action defines the return code , not the information to be printed to the console. Use stdout or yii\helpers\Console to output data
public function actionIndex(){
$fp = fopen("./file.txt", "w");
fwrite($fp, 'qweasdzxc123');
fclose($fp);
echo '1234';
return true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question