Hello Magento Friends,

Today I am going to explain How to Call Function from CLI Command in Magento 2.

You can also call a function using a block file from the CLI command to Magento 2. Check out the below steps to learn how to accomplish it.

Steps to Call Function from CLI Command in Magento 2:

Step 1: Firstly, you need to run the below command

Step 2: You need to call the block file by creating a di.xml file at the below path.

app\code\Vendor\Extension\etc\di.xml

And add the code as mentioned below

Step 3: Now create a file at the following path

app\code\Vendor\Extension\Console\Hicustomer.php

And add the below code

Conclusion:

Hence, this way you can Call Function from CLI Command in Magento 2. Check out the list of useful CLI commands for Magento 2. Share your queries via the comment section. Let your friends know about this solution. Stay tuned for the next one!

Happy Coding!

Click to rate this post!
[Total: 2 Average: 5]