我似乎无法找到一个关于如何在CakePHP 2 shell脚本上接收参数的简单具体示例。
class TestShell extends AppShell {
public function argumentTest(){
$parser = parent::getOptionParser();
$parser->addArgument('testArgument', array('short' => 't','help' => 'The test argument'));
var_dump($this->params);
}
}
然后我试着打电话给它:
控制台/蛋糕TestShell argumentTest --t 45
Console / cake TestShell argumentTest -t 45
Console / cake TestShell argumentTest --testArgument 45
Console / cake TestShell argumentTest -testArgument 45
以上所有内容我将此作为回复:
Usage:
cake lot_web_service [-h] [-v] [-q]
我做错了什么?
答案 0 :(得分:5)
您应该在设置选项解析器时设置参数:
public function getOptionParser() {
$parser = parent::getOptionParser();
//configure parser
return $parser;
}
这可确保在分派呼叫之前设置选项和参数。此外,从它的外观来看,您需要addOption()
而不是addArgument()
。