<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 創建自定義指令 第一步,創建一個自定義命令類文件,新建`application/common/command/Hello.php` ~~~ <?php namespace app\common\command; use think\console\Command; use think\console\Input; use think\console\input\Argument; use think\console\input\Option; use think\console\Output; class Hello extends Command { ? ? protected function configure() ? ? { ? ? ? ? $this->setName('hello') ->addArgument('name', Argument::OPTIONAL, "your name") ->addOption('city', null, Option::VALUE_REQUIRED, 'city name') ->setDescription('Say Hello'); ? ? } ? ? protected function execute(Input $input, Output $output) ? ? { $name = trim($input->getArgument('name')); $name = $name ?: 'thinkphp'; if ($input->hasOption('city')) { $city = PHP_EOL . 'From ' . $input->getOption('city'); } else { $city = ''; } ? ? ? ? $output->writeln("Hello," . $name . '!' . $city); ? ? } } ~~~ 這個文件定義了一個叫`hello`的命令,并設置了一個`name`參數和一個`city`選項。 第二步,配置`application/command.php`文件 ~~~ <?php return [ ? ? 'app\common\command\Hello', ]; ~~~ `V5.1.24+`版本開始,你可以定義為下面的方式提高性能。 ~~~ <?php return [ // 指令名 =》完整的類名 ? ? 'hello' => 'app\common\command\Hello', ]; ~~~ 第三步,測試-命令幫助-命令行下運行 ~~~ php think ~~~ 輸出 ~~~cmd Think Console version 0.1 Usage: ? command [options] [arguments] Options: ? -h, --help ? ? ? ? ? ?Display this help message ? -V, --version ? ? ? ? Display this console version ? -q, --quiet ? ? ? ? ? Do not output any message ? ? ? --ansi ? ? ? ? ? ?Force ANSI output ? ? ? --no-ansi ? ? ? ? Disable ANSI output ? -n, --no-interaction ?Do not ask any interactive question ? -v|vv|vvv, --verbose ?Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: ? build ? ? ? ? ? ? ?Build Application Dirs ? clear ? ? ? ? ? ? ?Clear runtime file hello? ? ? ? ? ? ? Say Hello ? help ? ? ? ? ? ? ? Displays help for a command ? list ? ? ? ? ? ? ? Lists commands ?make ? make:controller ? ?Create a new resource controller class ? make:model ? ? ? ? Create a new model class ?optimize ? optimize:autoload ?Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production. ? optimize:config ? ?Build config and common file cache. ? optimize:schema ? ?Build database schema cache. ~~~ 第四步,運行`hello`命令 ~~~cmd php think hello ~~~ 輸出 ~~~ Hello thinkphp! ~~~ 添加命令參數 ~~~cmd php think hello liuchen ~~~ 輸出 ~~~ Hello liuchen! ~~~ 添加`city`選項 ~~~cmd php think hello liuchen --city shanghai ~~~ 輸出 ~~~ Hello thinkphp! From shanghai ~~~ >[danger] 注意看參數和選項的調用區別 > ## 在控制器中調用命令 支持在控制器的操作方法中直接調用命令,例如: ~~~ <?php namespace app\index\controller; use think\Console; use think\Controller; class Index extends Controller { public function hello($name) { $output = Console::call('hello ' . $name); return $output->fetch(); } } ~~~ 訪問該操作方法后,例如: ~~~ http://tp5.com/index/index/hello/name/thinkphp ~~~ 頁面會輸出 ~~~ Hello thinkphp! ~~~ > 一旦在控制器中調用命令,并不會生成cli命令行日志,而是在普通的web日志中記錄。 > ## 快速生成指令(`V5.1.24+`) `V5.1.24+`版本開始,你可以通過命令行指令快速生成一條指令,包括指令類文件,例如: ~~~ php think make:command First first ~~~ `First`表示類名,實際生成的指令類則是`app\command\First`(自動生成的指令類的命名空間默認都是 `app\command`)。 `first`表示指令名,建議統一使用小寫,如果不傳入該參數,則默認用類名的小寫作為指令名。 為了讓指令可以無需定義自動調用,需要在你的應用配置的`console.php`配置文件中,增加下面的配置參數: ~~~ 'auto_path' => env('app_path') . 'command/', ~~~ 配置后, 你可以在命令行測試下剛才新生成的指令。 ~~~ php think first ~~~ 輸出結果為: ~~~ first ~~~ 你可以編輯`app\command\First`類,完成實際的指令任務。 >[danger] 注意,如果你生成了指定命名空間的指令,但又不是你配置的自動加載目錄,那么仍然需要在`command.php` 文件中定義指令。 > 如果需要生成一個指定的命名空間,可以使用: ~~~ php think make:command app\index\Second second ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看