2014-10-28 80 views
2

我試圖做一個cron應用程序在我ZF2項目,但參數無效它給了我永遠以下消息:在Zend框架控制檯的cron路線2

失敗原因:無效的參數或不提供參數

我的代碼是這樣的:

module.config.php

'controllers' => array(
     'invokables' => array(
      'Sync\Controller\Cron' => 'Sync\Controller\CronController', 
      'Sync\Controller\Index' => 'Sync\Controller\IndexController' 
     ), 
    ), 
'console' => array(
     'router' => array(
      'routes' => array(
       'user-reset-password' => array(
        'options' => array(
         'route' => 'user resetpassword [--verbose|-v] <userEmail>', 
         'defaults' => array(
          'controller' => 'Sync\Controller\Index', 
          'action' => 'password' 
         ) 
        ) 
       ), 
       'cron' => array(
        'options' => array(
         'route' => 'cron [full|center]', 
         'defaults' => array(
          'controller' => 'Sync\Controller\Cron', 
          'action' => 'full' 
         ) 
        ) 
       ) 
      ) 
     ) 
    ) 

CronController.php

class CronController extends AbstractActionController 

{

public function fullAction() 
{ 
    $request = $this->getRequest(); 
    if (!$request instanceof ConsoleRequest) { 
     throw new \RuntimeException('You can only use this action from a console!'); 
    } 
    return("hi"); 
} 

public function centerAction() 
{ 

} 

}

+2

請問你的控制檯命令是什麼樣子?你是否用控制檯調用它? – cptnk 2014-10-28 10:37:16

+0

我的命令是:./bin/guido cron – 2014-10-29 09:11:17

+0

你必須把它叫做槽位zf2公共文件夾中的index.php。它應該是這樣的:「/whatever/www/zf2/public/index.php cron full」 – cptnk 2014-10-29 09:48:04

回答

0

考慮到匹配的php二進制文件,然後你可以從你的應用程序文件夾調用路徑:

php public/index.php cron full

或者只是

php public/index.php cron(因爲路徑默認爲fullAction)