1

I would like to create a custom console command for my Craft 3 plugin. I've looked at the Yii docs and understand commands are defined using controllers extending \yii\console\Controller but cannot work out how these controllers should be registered with the application.

To register site routes in Craft 3, we listen for the UrlManager::EVENT_REGISTER_SITE_URL_RULES event and then define rules. What's the equivalent for registering console commands?

Thanks

1

What's the equivalent for registering console commands?

You don't need to listen to an event to create a console command. Assuming your namespacing and autoloading is set up correctly, they'll "just work".

I'd suggest going over to https://pluginfactory.io/ and select with Craft 3 plugin or module and tick the "Console Commands" checkbox to see a working example of how the files and structure is set up.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.