我目前正试图让控制台路由使用默认值
我的路线配置为:
'console' => array(
'router' => array(
'routes' => array(
'fetch-rapportage' => array(
'options' => array(
'route' => 'rapportage --type= [--hid=]',
'defaults' => array(
'controller' => 'ZetaRapportage\Controller\Test',
'action' => 'generate',
'hid' => false,
)
)
)
)
)
),
现在我运行以下命令
cron rapportage --type virtual
结果按预期进行
object(Zend\Stdlib\Parameters)#96 (1) {
["storage":"ArrayObject":private]=>
array(8) {
[0] => string(10) "rapportage"
[1] => string(6) "--type"
[2] => string(7) "virtual"
["type"] => string(7) "virtual"
["rapportage"] => bool(true)
["controller"] => string(30) "ZetaRapportage\Controller\Test"
["action"] => string(8) "generate"
["hid"] => bool(false)
}
}
现在当我添加可选标志--hid时,结果不符合预期
命令:
cron rapportage --type virtual --hid 100
输出
object(Zend\Stdlib\Parameters)#96 (1) {
["storage":"ArrayObject":private]=>
array(10) {
[0] => string(10) "rapportage"
[1] => string(6) "--type"
[2] => string(7) "virtual"
[3] => string(5) "--hid"
[4] => string(3) "100"
["type"] => string(7) "virtual"
["hid"] => bool(false) <-- expected value 100
["rapportage"] => bool(true)
["controller"] => string(30) "ZetaRapportage\Controller\Test"
["action"] => string(8) "generate"
}
}
所以我现在处于“等待!!!” - 模式并且无法找出原因和方法?!?!?这里有人可以指出问题
答案 0 :(得分:0)
没关系,这是ZF2中的一个错误,它将在2.2.0中修复
答案 1 :(得分:0)
如果您希望在等待2.2.0发布时立即为您解决问题,请使用此功能(假设您运行的是2.1.5-最新版本):
diff --git a/library/Zend/Mvc/Router/Console/Simple.php b/library/Zend/Mvc/Router/Console/Simple.php
index 4105dfb..7c925df 100644
--- a/library/Zend/Mvc/Router/Console/Simple.php
+++ b/library/Zend/Mvc/Router/Console/Simple.php
@@ -797,7 +797,7 @@ class Simple implements RouteInterface
return null; // there are extraneous params that were not consumed
}
- return new RouteMatch(array_replace($matches, $this->defaults));
+ return new RouteMatch(array_replace($this->defaults, $matches));
}
/**