【发布时间】:2014-10-28 10:33:39
【问题描述】:
我正在尝试在我的 zf2 项目中制作一个 cron 应用程序,但它总是给我以下消息:
失败原因:参数无效或未提供参数
我的代码是这样的:
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()
{
}
}
【问题讨论】:
-
你的控制台命令是什么样子的?你是在控制台满的情况下调用它吗?
-
我的命令是:./bin/guido cron
-
您必须通过 zf2 公共文件夹中的 index.php 调用它。它应该是这样的:“/whatever/www/zf2/public/index.php cron full”
-
如果我执行这个命令,结果是一样的
-
你不应该
return字符串“hi”。你应该改为print或echo来查看结果。
标签: php console cron zend-framework2