Spurious
Spurious

Reputation: 1995

Run command in cmd.exe

I am looking to run a command in the cmd.exe from the yii2 application. I am on localhost and have admin rights.

The file I am trying to run the command from has the following path: C:\Server\htdocs\hr\commands\EmployeecronController.php

The code looks like this:

class EmployeecronController extends Controller
{
    public function actionIndex()
    {
       [Code]   
    }
}

This is what I enter into the console:

cmd Error message

Upvotes: 0

Views: 120

Answers (2)

Spurious
Spurious

Reputation: 1995

Ok, for me the problem was the following, I had to enter it like this: C:\Server\htdocs\hr> C:/Server/php/php.exe yii employeecron

Upvotes: 0

arogachev
arogachev

Reputation: 33538

1) Make sure you placed controller in right folder:

  • for basic application - commands folder;
  • for advanced application - console/controllers folder.

2) Make sure correct namespace is specified:

  • for basic application - namespace app\commands;;
  • for advanced application - namespace console/controllers;

3) You need to call it like that:

php yii employeecron/index

or

yii employeecron/index

You can omit index because it's default action:

php yii employeecron

For complex controller and action names, for example LongContollerName you need to separate it with dashes (as with regular web controllers):

php yii long-controller-name/long-action-name

Upvotes: 1

Related Questions