{"id":7859,"date":"2021-05-02T11:42:33","date_gmt":"2021-05-02T11:42:33","guid":{"rendered":"https:\/\/www.bay20.com\/?p=7859"},"modified":"2025-05-21T16:34:12","modified_gmt":"2025-05-21T10:49:12","slug":"wie-hinzufugen-neuer-konsole-befehl-in-magento-2","status":"publish","type":"post","link":"https:\/\/www.bay20.com\/de\/wie-hinzufugen-neuer-konsole-befehl-in-magento-2\/","title":{"rendered":"Wie man einen neuen Konsolenbefehl in Magento 2 hinzuf\u00fcgt"},"content":{"rendered":"\n<p>Erstellen Sie ein neues Modul mit <strong>CustomCommandLine_ConsoleCommand.<\/strong><\/p>\n\n\n\n<p><strong>Schritt 1:<\/strong> Erstellen Sie die Datei <strong>registration.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomCommandLine\/ConsoleCommand\/registration.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n\t\\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n\t'CustomCommandLine_ConsoleCommand',\n\t__DIR__\n);<\/code><\/pre>\n\n\n\n<p><strong>Schritt 2:<\/strong> Erstellen Sie die Datei <strong>module.xml.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomCommandLine\/ConsoleCommand\/etc\/module.xml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\"&gt;\n    &lt;module name=\"CustomCommandLine_ConsoleCommand\" setup_version=\"1.0.0\"&gt;\n    &lt;\/module&gt;\n&lt;\/config&gt;<\/code><\/pre>\n\n\n\n<p><strong>Schritt 3:<\/strong> Erstellen Sie die Datei <strong>di.xml.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomCommandLine\/ConsoleCommand\/etc\/di.xml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\"&gt;\n    &lt;type name=\"Magento\\Framework\\Console\\CommandList\"&gt;\n        &lt;arguments&gt;\n            &lt;argument name=\"commands\" xsi:type=\"array\"&gt;\n               &lt;item name=\"clean_generation\" xsi:type=\"object\"&gt;CustomCommandLine\\ConsoleCommand\\Model\\Generation&lt;\/item&gt;\n            &lt;\/argument&gt;\n        &lt;\/arguments&gt;\n    &lt;\/type&gt;\n&lt;\/config&gt;<\/code><\/pre>\n\n\n\n<p><strong>Schritt 4:<\/strong> Erstellen Sie die Datei <strong>Generation.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomCommandLine\/ConsoleCommand\/Model\/Generation.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace CustomCommandLine\\ConsoleCommand\\Model;\n\nuse \\Symfony\\Component\\Console\\Command\\Command;\nuse \\Symfony\\Component\\Console\\Input\\InputInterface;\nuse \\Symfony\\Component\\Console\\Output\\OutputInterface;\nclass Generation extends Command\n{\n    protected function configure()\n    {\n        $this-&gt;setName('generation:clean')-&gt;setDescription('Clean Generation Folder');\n        parent::configure();\n    }\n    protected function execute(InputInterface $input, OutputInterface $output)\n{   \n        system(\"rm -r generated\/*\");\n        $output-&gt;writeln('Generation Folder Clean Successfully.');\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Schritt 5:<\/strong> Als N\u00e4chstes m\u00fcssen wir \u00fcberpr\u00fcfen, ob Ihr neuer Befehl in der Befehlsliste angezeigt wird. Dazu m\u00fcssen Sie den folgenden Befehl ausf\u00fchren.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php bin\/magento<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"372\" src=\"https:\/\/www.bay20.com\/wp-content\/uploads\/2021\/03\/19-980x372.png\" alt=\"\" class=\"wp-image-7860\" srcset=\"https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/19-980x372.png 980w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/19-300x114.png 300w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/19-800x304.png 800w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/19-768x291.png 768w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/19-1536x583.png 1536w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/19-1000x379.png 1000w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/19.png 1892w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/figure>\n\n\n\n<p><strong>Schritt 6:<\/strong> Zum Schluss m\u00fcssen Sie den Befehl ausf\u00fchren.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php bin\/magento generation:clean<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"385\" src=\"https:\/\/www.bay20.com\/wp-content\/uploads\/2021\/03\/20-980x385.png\" alt=\"\" class=\"wp-image-7861\" srcset=\"https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/20-980x385.png 980w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/20-300x118.png 300w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/20-800x315.png 800w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/20-768x302.png 768w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/20-1536x604.png 1536w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/20-1000x393.png 1000w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2021\/03\/20.png 1879w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/figure>\n\n\n\n<p><strong>Bitte kontaktieren Sie uns unter <strong><a href=\"mailto:manish@bay20.com\">manish@bay20.com<\/a><\/strong> oder rufen Sie uns unter <strong><a href=\"https:\/\/api.whatsapp.com\/send?phone=+918800519180&amp;text=Hi,%20I%20contacted%20you%20through%20your%20website.\" target=\"_blank\" rel=\"noreferrer noopener\">+91-8800519180<\/a><\/strong> an, wenn Sie Unterst\u00fctzung f\u00fcr Magento 2 ben\u00f6tigen. Sie k\u00f6nnen auch die <strong><a href=\"https:\/\/www.bay20.com\/de\/magento-entwicklungsunternehmen\/\">Magento2<strong>-Entwicklungsseite<\/strong><\/a><\/strong> besuchen, um die von uns angebotenen Dienstleistungen zu \u00fcberpr\u00fcfen.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You need to check if your new command is shown in the command list or not for that you need to run the following command.<\/p>\n","protected":false},"author":1,"featured_media":8410,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77,79],"tags":[],"class_list":["post-7859","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","category-magento-anleitung"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/comments?post=7859"}],"version-history":[{"count":7,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7859\/revisions"}],"predecessor-version":[{"id":17296,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7859\/revisions\/17296"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media\/8410"}],"wp:attachment":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media?parent=7859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/categories?post=7859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/tags?post=7859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}