您可以从 yii2-basic 运行控制台作业吗? [英] Can you run console jobs from yii2-basic?

查看:30
本文介绍了您可以从 yii2-basic 运行控制台作业吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Yii2-advanced 能够运行控制台作业 (php yii controllername) 但我想知道基本应用程序是否具有相同的能力?我注意到 config 文件夹中有一个 console.php 文件,但似乎无法运行作业.

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.

如果可能的话,有人可以举个例子 - 控制器去哪里(因为我把它放在控制器中,但我在尝试 php yii 测试时收到消息错误:未知命令测试")

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)

感谢任何帮助.

推荐答案

是的,基本模板中也存在相同的功能.

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

但是,它的组织方式略有不同.

However, it's organized a bit differently.

默认情况下,控制台控制器位于 commands 文件夹中(您可以通过编辑此设置来更改它:'controllerNamespace' => 'app\commands').

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

通过您提到的 config/console.php 管理配置.

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

例如你可以看看 HelloController 默认是模板自带的.

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.

您可以使用 php yii 命令列出所有可用命令.

You can list all available commands with php yii command.

这篇关于您可以从 yii2-basic 运行控制台作业吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆