9

I am aware that Yii2-advanced has the ability to run console jobs (php yii controllername) but I was wondering if the basic app has the same ability? I notice a console.php file in the config folder, but cannot seem to get the jobs to run.

If it is possible, can someone give an example - where does the controller go (since I put it in controllers, but I get the message 'Error: Unknown command test' when trying php yii test)

Any help appreciated.

Martin
  • 949
  • 1
  • 10
  • 15
  • I think you really meant console commands, not console jobs. I have a jobs directory that holds all the background jobs implemented using ResQue and it has a different syntax to run them. – SenG Jan 31 '16 at 14:25

1 Answers1

10

Yes, the same functionality exists in the basic template too.

However, it's organized a bit differently.

By default the console controllers are located in commands folder (you can change that by editing this setting: 'controllerNamespace' => 'app\commands').

Configuration is managed through config/console.php that you mentioned.

As for example you can take a look at HelloController which comes with template by default.

You can find more info in according official docs section.

As for you error, accurately check controller name and its action names, most likely the problem is there.

Update: Make sure you have at least one action in this controller, otherwise the same error ("Unknown command") will appear.

You can list all available commands with php yii command.

arogachev
  • 33,150
  • 7
  • 114
  • 117
  • 3
    The docs are useless. They don't mention `commands/` path or `controllerNamespace` at all. – Chloe Apr 28 '15 at 21:33