0

I'm currently trying to get a console route to work with default values

my route is curently configured as:

'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,
                    )
                )
            )
        )
    )
), 

Now when i run the following command

cron rapportage --type virtual

the result comes in as expected

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)
        }
}

Now when i add the optional flag --hid the result is not as expected

command:

cron rapportage --type virtual --hid 100

output

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"
        }
}

So i'm currently in "wait-whut!!!"-mode and cant' figure out why and how?!?!? Someone here that can put a finger on the problem

4

2 回答 2

0

没关系这是 ZF2 中的一个错误,它将在 2.2.0 中修复

https://github.com/zendframework/zf2/pull/4295

于 2013-05-02T09:06:57.347 回答
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));
     }

     /**
于 2013-05-03T02:48:38.070 回答