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.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-62846bfaea2b0362819391/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...