Dani Tome
Dani Tome

Reputation: 503

Invalid arguments console error in Zend Framework 2

I'm trying to make a crone app in my zend framework application. The problem is when I try to running it. It shows me the following error and the command is:

Command: php public/index.php cron full

Result: Reason for failure: Invalid arguments or no arguments provided

module.config.php:

array(
    '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',
                        '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()
{

}

}

Module.php

public function getConsoleUsage(Console $console)
{
    return array(
        // Describe available commands
        /*$console->colorize('User resetpassword [--verbose|-v] EMAIL ->Reset password for a user', Color::YELLOW),
        // Describe expected parameters
        array($console->colorize('EMAIL', Color::GREEN), 'Email of the user for a password reset'),
        array('--verbose|-v', '(optional) turn on verbose mode'),*/
        $console->colorize('Cron [full|center]', Color::YELLOW),
        array($console->colorize('cron full', Color::GREEN), 'Execute full cron job'),
        array($console->colorize('cron center', Color::GREEN), 'Execute center cron job'),
    );
}

public function getConfig()
{
    return include __DIR__ . '/config/module.config.php';
}

public function getAutoloaderConfig()
{
    return array(
        'Zend\Loader\ClassMapAutoloader' => array(
            __DIR__ . '/autoload_classmap.php',
        ),
        'Zend\Loader\StandardAutoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
            ),
        ),
    );
}

Upvotes: 2

Views: 3260

Answers (1)

Purple Hexagon
Purple Hexagon

Reputation: 3578

The error

"Reason for failure: Invalid arguments or no arguments provided"

will happen if the console route has not been registered.

Is that your full module.config.php? I assume you just excluded the return statement for the array from the code snippet and it really is there in the module.config.php in your application?

Also is this in a separate module? Have you definitely included the module in config/application.config.php

as everything seems ok with the code

Upvotes: 2

Related Questions