I have built a custom module with some custom controller actions - some of which I would like to run via console, but I am not sure what the path/command should be for running these actions?
In my routes.php
I have:
'action/my-action' => 'custom-module/custom-controller/custom-action'
Is it based on the URL route, or the module command, or something else?
Things like ./craft action/my-action
or ./craft custom-module/custom-controller/custom-action
do not work and return:
Unknown command: custom-module/custom-controller/custom-action
Caused by: Exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "custom-module/custom-controller/custom-action".'
We have got the following in our module which I thought would make web controllers "just work" but it does not:
if (Craft::$app->getRequest()->getIsConsoleRequest()) {
$this->controllerNamespace = 'custom-module\\console\\controllers';
}
And an example controller/action: https://gist.github.com/iamkeir/5929a7da368e9b74e93c330f504d0bd1
Thanks!