How to make a console call in Yii2 ? Lord, please tell

  1. installed the YII2 basic framework on OpenServer , I see a test site (mysite.local)
  2. open CMD, go to the URL of my site (c: \ My \ OpenServer \ OpenServer \ domains \ mysite.local> _)
  3. I enter

    yii <hello> [-m=hello] 

    getting

    Cannot find the specified file.

As usual, the problem of discovering a new one. Tell me how to make a console appeal in Yii2 ?

UPD

at php yii I get on

 Parse error: syntax error, unexpected '[' in C:\My\OpenServer\OpenServer\domains\mysite.local\vendor\guzzlehttp\psr7\src\functions.php on line 78 

I enter the command eats, but without brackets

  • there are many nuances. do you type exactly as you wrote? Those. yii <hello> [-m=hello] with all the brackets? Because it is necessary without them ... Are you in the console folder created HelloController ? what is written in it? - Alexey Shimansky
  • eats, but without brackets, file eats, but created in the image yiiframework.com/doc-2.0/… - serg
  • при php yii попадаю на Parse error: syntax error, unexpected '[' - PHP version should be> = 5.4 - Alexey Shimansky
  • I tried on 5.5 / 5.6 - serg
  • Well, this is about parsing errors ..... should work with 5.5 / 5.6 ........ and what version of the framework? you can look like this: Yii::getVersion(); - Alexey Shimansky

1 answer 1

You should create the HelloController.php file in the app/commands folder:

 <?php namespace app\commands; use yii\console\Controller; class HelloController extends Controller { public $message; public function options($actionID) { return ['message']; } public function optionAliases() { return ['m' => 'message']; } public function actionIndex() { echo $this->message . "\n"; } } 

And only then your team will work. Most likely you read the official guide but did not finish reading or something else, try.

  • This is the file! I don't understand why it doesn't work - serg
  • one
    the solution is: open the OpenServer console, because in CMD version PHP 5.3! - serg
  • @serg can stand before the openserver something and register in variable environments ?, it is logical that when working with openserver it is necessary to use the console just for it ..... or in the variable environments to prescribe the path to the desired version> _ < - Alexey Shimansky