ZF2 Unlimited params用于控制台路由

时间:2014-01-16 10:52:55

标签: php console routes zend-framework2

我有这样的路线:

'cronExec' => array(
    'options' => array(
        'route' => 'exec [<commands>]',
        'defaults' => array(
            'controller' => 'Cron\Controller\Commands',
            'action' => 'exec'
        )
    )
),

这将抓住:

  • execCmd
  • execCmd commandNameHere

但是我还希望用无限数量的参数来捕捉第二个:

  • execCmd commandNameHere --x = y --a = b --c = 1
  • execCmd commandNameHere --param1 = 1 --param2 = 0

或以任何其他方式允许我将无限的,未知的命名参数发送到指定的命令,但仅当execCmd设置在它之前

1 个答案:

答案 0 :(得分:2)

'cronExec' => array(
    'type' => 'Catchall',
    'options' => array(
        'route' => 'exec',
        'defaults' => array(
            'controller' => 'Cron\Controller\Commands',
            'action' => 'exec'
        )
    )
),

<强> UPDATE1

或者您可以在单个参数中传递任何参数。

'cronExec' => array(
    'options' => array(
        'route' => 'exec [--params=]',
        'defaults' => array(
            'controller' => 'Cron\Controller\Commands',
            'action' => 'exec'
        )
    )
),

称之为

php public/index.php exec --params="--any --other --params"

并在控制器中使用$this->params('params')或其他任何内容getopt解析。

相关问题