Here is a simple hello world command run using the command
– Please create the following module for command :
app/code/Vendor/Module/registration.php
1 2 3 4 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Vendor_Module" setup_version="0.1.0"/> </config> |
app/code/Vendor/Module/Model/Generation.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
namespace Vendor\Module\Model; use \Symfony\Component\Console\Command\Command; use \Symfony\Component\Console\Input\InputInterface; use \Symfony\Component\Console\Output\OutputInterface; class Generation extends Command { protected function configure() { $this->setName('custom:create') ->setDescription('The description of you command here!'); parent::configure(); } protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Hello World!'); } } |
app/code/Andre/Tools/etc/di.xml
1 2 3 4 5 6 7 8 9 10 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\Console\CommandList"> <arguments> <argument name="commands" xsi:type="array"> <item name="create" xsi:type="object">Vendor\Module\Model\Generation</item> </argument> </arguments> </type> </config> |
Now, run upgrade command to register module : bin/magento setup:upgrade
To run the command, just create :
1 |
bin/magento custom:create. |
Then add your own logic under the execute() method.
Please let us know if this article is helpful to you.
[crayon-63e0a170c0d9b382448309/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.