
一部のシナリオでは、コマンド ラインからコードを呼び出す必要があります。
- まず、application\command でコードを呼び出す必要があります。ディレクトリに新しい hello.php を作成します (存在しない場合は作成します):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\Request;
class hello extends Command {
protected function configure()
{
$this
->setName('hello')
->setDescription('定时任务微服务.')
->setHelp( "定时任务微服务 无参数" );
}
protected function execute(Input $input , Output $output )
{
echo 'hello world';
}}
|
ログイン後にコピー
- application/command.php を変更します (存在しない場合は作成します)
1 2 3 | <?php
return [
"app\command\hello" ,];
|
ログイン後にコピー
- cd toプロジェクトのルート ディレクトリに移動し、コマンド ラインで # と入力します。
##OK、 の呼び出しに成功しました
-
#関連学習の推奨事項:
PHP プログラミングの入門から熟練度まで
以上がThinkPHP でコマンドライン (cli) think コールを使用する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。