We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
How to Add Command line in to Console CLI in Magento 2
Follow these steps add the command line in to console CLI in magento 2.
- create the di.xml
- create command class
Create di.xml file
In di.xml file you will define the command.
Directory
app/code/VendorName/ModuleName/etc/di.xml
Content of di.xml
<?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="demoCommand" xsi:type="object">VendorName\Module\Console\DemoCommand</item>
</argument>
</arguments>
</type>
</config>
Create Command Class
Directory
app/code/VendorName/ModuleName/Console/DemoCommand.php
Content of DemoCommand.php
<?php
namespace VendorName\ModuleName\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DemoCommand extends Command
{
protected function configure()
{
$this->setName('demo:command');
$this->setDescription('Demo command line');
parent::configure();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("The Command Created");
}
}
Now flush/clear the magento cache,
php bin/magento cache:clean
Run the created commmand:
php bin/magento demo:command
If you are looking for Magento Developers, visit Magento Developer Agency.
Recent post
new admin user
magent 2.4
add new admin user using front-end
add new admin user using command line
admin user role
user role in magneto 2.4
magento 2.4
custom attribute
related products
product page
category
sub-category
how to add simple products
simple products
products in magento2
how to add simple products in magento2
Magento
store url
Full Page Cache
Translate CMS Pages
configurable product
how to add configurable product in magento2
magento2
magento2 products
eCommerce
Product Attribute Set
favicon
Import Products
Rss Feeds
how to configure rss feeds in magento 2
configuration of rss feeds
magento 2 structure
magento directory structure
module structure
magento design structure
theme structure of magento 2
e-commerce
magento2 agency
product
security
magento 2
attribute
CMS
block
admin-user
admin-role
product-attribute
page-cache
customize url
store
base url
CMS pages
basic structure
theme structure
design structure
root folder
migration
upgraded
speed up
improvements
seperate database
magento 1
shopify
new admin
create admin
elasticsearch
catalog search
simpleproduct
css
javascript
merge css
merge javascript
enable css
enable javascript
newsletter
php 8
compatibility
Multiple Stores
remarketing
boost sales
upsell-products
cross-sell products
payment method
check method
money order method
stock
product stock
configuration
Secure your Admin
VAT
tax classes
email logo
shipping policy
create new API
configure free shipping method
delete order in magento 2
features
magento store scope
cdn
cms-page
ux
uxdesign
magento-ux
ui-vs-ux
uidesign
user experience
product-list
uxscope
promote
marketing
SEO
Configure Email
Order Confirmation
redirect buyer
header
footer
layered-navigation
magento 2 store in multiple languages
inbox
message
Cancel order
edit order
magento and microsoft dynamics
integration
magento-theme
magento-layout
layout
magento-commerce
remove order
magento-store
magento-website
switch to Magento
Welcome message
Influence of Marketing
stock message
contact us form
contact email
admin login captcha
single store mode
single store
store view
magento installation
flat rate
shipping method
contact form
recaptcha
marketing plan
CSP
XSS
adding store view
magneto 2
B2B
B2C
D2C
Magento Commerce
Magento Commerce Cloud
guidepost
Small Business
Country Options
Magento Open Source
Product Search
magento-2-tutorial
rewrites
ecommerce agency
schedule design
customer account
magento hosting
hosting
magento configuration
Insert Images
magento developer
sales email
email configuration
Advanced Inventory
Warehouse
copyright
magneto copyright
copyright notice
update copyright
magento email store
store email address
update email address
Locale Option
programmatically
module
magento module
CMS Static Block
controller in magento2
magento controller
Override php file
plugin
plugin in magento2
helper function
magenot 2
call helper in phtml file
Backup Store
Magento Admin Panel
admin menu
model in magento
invoice in magento2
create invoice
Dependency Injection
di.xml
cronjob
cronjob in magento2
Api
events
event in magento2
Change
Default Icon
Menu Items
Backend
widget in magento 2
widget
custom widget
Add Store Demo
Api in magento 2
Run Compile Commad
custom tab
Mass Actions in magento 2
override classes
preference
helper in magento2
featured products
custom helper
checkout in magento 2
checkout page
customer collection
product collection
wishlist products collection
order collection
review in magento 2
rating in magento 2
review collection
rating collection
recent product collection
ui form
form in magento 2
magento 2 configuration
magento 2 fields
delete action in magento 2
edit action in magento 2
disable payment method
custom discount
virtual type
log
custom log
log file
eav attribute
installschema
database
product schema
production mode
indexer
reindexer
reindex magento 2
indexer magento 2
magento2 installation
email customization
custom email
email in magento 2
indexing
cart rules
catalog price rule
magento 2 catalog
currency in magento 2
command
console command
command in magento 2
store information in magento 2
extend layout
homepage
url in magento 2
error
google shopping feed
feed
magento2 feed
reindex magento 2 programatically
custom indexer
custom indexer for magneto 2
Magento 2 UX
Benefits of Magento 2 UX
magento 2 edit order
cancle order in magento 2
remove order in magento 2
update order in magento 2
magento 2 free shipping rule