Console route in Zend3 is not matching
Asked Answered
I

1

5

I have a console route in my module.config.php file

'console' => [
        'router' => [
            'routes' => [
                'remove' => [
                    'type'    => 'simple',
                    'options' => [
                        'route'    => 'remove [force] [init]',
                        'defaults' => [
                            'controller' => Controller\CliController::class,
                            'action'     => 'remove',
                        ],
                    ],
                ]
            ]
        ]
    ]

And my Controller that has method removeAction()

namespace Controller;

class CliController extends AbstractActionController
{
    public function removeAction()
    {
        $this->logger->debug('I am in');
    }
}

When i do command php public/index.php remove force or php public/index.php remove I never get sent to do controller and there is no error or any output. So am I doing the matching wrong?

It's like app is not realizing it was called from terminal. Sometimes it just returns html if i remove getConfig method from Module.php within my module/MyModulefolder.

Imtiaz answered 6/9, 2016 at 7:15 Comment(0)
I
9

The problem was that i didn't include 'Zend\Mvc\Console' in modules.config.php so that's way it wasn't reacting when it was given a command from console.

After putting this into array in modules.config.php everything is working.

Rookie mistake.

Imtiaz answered 6/9, 2016 at 10:59 Comment(2)
In my case I had to install zend-console before and add to module.config.php as you said. To install use composer require zendframework/zend-mvc-consoleDoreathadoreen
Thanks, that was exactly my problem.Groves

© 2022 - 2024 — McMap. All rights reserved.