Can you run console jobs from yii2-basic?

▼魔方 西西 提交于 2019-12-22 04:33:09

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/29090479/can-you-run-console-jobs-from-yii2-basic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!