2016-04-13 48 views
0

我在module.config.php文件的路線是這樣的:如何在ZF2 ..中使用控制檯路由中的約束?

'console' => array(
     'router' => array(
      'routes' => array(
       'updatecron' => array(
        'options' => array(
         'route' => 'cronupdate', 
         'defaults' => array(
          'controller' => 'Application\Controller\Cron', 
          'action' => 'update' 
         ) 
        ) 
       ) 
      ) 
     ) 
    ) 

現在我需要一個動態值傳遞給這個動作像我們這樣做,我們使用的限制像低於正常路線:

'route' => 'cronupdate[/:id][/]', 
'constraints' => array(
    'id' => '[0-9]+', 
), 

但它不工作,並拋出錯誤。雖然谷歌搜索我在ZF2 github issues這樣找到了一種方法某處:

'console' => array(
     'router' => array(
      'routes' => array(
       'updatecron' => array(
        'options' => array(
         'route' => 'cronupdate <id>', 
         'constraints' => array(
          'id' => '[0-9]+', 
         ), 
         'defaults' => array(
          'controller' => 'Application\Controller\Cron', 
          'action' => 'update' 
         ) 
        ) 
       ) 
      ) 
     ) 
    ) 

但也不能正常工作。請建議我如何才能做到這一點。

注意: - 我需要通過exec函數調用它,這就是爲什麼使用控制檯路由。

+0

這是編寫id的方法:''route'=>'cronupdate [/:id]',' – Unex

+0

您寫了*「雖然使用Google搜索我在ZF2的某個地方找到了方法」* ...您在哪裏找到這個?添加一個參考將是很好的。我很難想象官方文檔會提供這種路由。路由ID應定義像@Unex寫... – Wilt

+0

@Wilt我沒有在我的問題中提到,我發現在官方文檔中的東西,請檢查此鏈接,用戶確認其在許多情況下爲他工作https: //github.com/zendframework/zf2/issues/6316 – Ritesh

回答

0

我在我的評論中錯了路線ID。你做了正確的控制檯路線!

我會說這個問題可能是由於控制檯路由不支持constraints。我至少沒有找到任何文檔,並且他們也沒有提到對控制檯路由添加約束......

我也從來沒有看到任何用戶案例,其中約束被添加到控制檯路由。不知道爲什麼?也許在官方的ZF2倉庫中詢問GitHub和/或提出功能請求會很有趣。