thinkphp5 自定义命令行中input传值问题,官方文档只列出了如何生成命令行,但是针对input的传值没有找到任何说明文档,因此本文主要针对input的传值问题进行说明
/**
*
*
* @author moshao
* @link http://gmail.com/
* @copyright 2018 moshao all rights reserved.
* @license http://www.apache.org/licenses/LICENSE-2.0
*/
namespace app\cli\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\Db;
use think\Config;
class Chapter extends Command {
protected $pernum = 100;
protected function configure() {
//设置参数
$this->addArgument('beginid', Argument::REQUIRED); //必传参数
$this->addArgument('endid', Argument::OPTIONAL);//可选参数
//选项定义
$this->addOption('message', 'm', Option::VALUE_REQUIRED, 'test'); //选项值必填

本文探讨了在ThinkPHP5自定义命令行中如何处理Input传值的问题,特别是针对参数和选项的设置与获取。通过示例代码展示了如何使用`$input->getArguments()`和`$input->getOptions()`来获取输入值,并提供了正确的命令行调用格式。在传参时应注意参数间用空格分隔,而选项则需配合`-m`或`-s`等标志。错误的输入会导致运行时错误。
最低0.47元/天 解锁文章
4268

被折叠的 条评论
为什么被折叠?



