![]() In this class, we need to declare 2 methods: Our class CustomCommand must extend core class Symfony\Component\Console\Command\Command. $output->writeln("Welcome to Magenest!") Protected function execute(InputInterface $input, OutputInterface $output) * method will run when the command is called via console ![]() $this->setDescription('Demo add custom command') Magento 2 uses Symfony Console component for console commands, therefore we need to use several Symfony functions in our class: setName('example:customcommand') Now let's create our CustomCommand class. Magento recommends putting command classes under /Command folder. In this file, we declare a class CustomCommand to define command syntax and command action. Magenest\CommandLine\Console\CustomCommand ![]() Here are the steps to create a custom command line: Step 1: Declare a custom command class in the file etc/di.xml In this article, we use a module called Magenest_CommandLine. These command lines are familiar with Magento developers when working with Magento, such as:īefore we start, you should know to create a simple module. In this article, we will learn how to add a custom command line in console to perform Magento 2 functions.
0 Comments
Leave a Reply. |