F
F
flametrong2017-05-24 13:07:06
Yii
flametrong, 2017-05-24 13:07:06

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;
  }
}

Actually the result is, but partial. A file file.txt is created in the YII root, everything is cool, i.e. the script works, but! in the console rerurn does not return anything
Lord, tell me how to display return in the console? Maybe add something in the settings?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
davidnum95, 2017-05-24
@flametrong

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;
    }

M
Maxim Fedorov, 2017-05-24
@qonand

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

M
Maxim Timofeev, 2017-05-24
@webinar

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 question

Ask a Question

731 491 924 answers to any question