Question

I am new to Magento, and I am trying to do add my very first module. I tried to follow two tutorials that show how to create a "Hello World" module, which basically shows a 'Hello World!' message on the website; I have installed the sample data. Both sample page and admin page are working fine. What I have been trying is the following:

  1. Create folder Magentoexplorer (http://magentoexplorer.com/how-to-build-hello-world-magento-2-module-from-scratch)

  2. Inside this folder, there is another folder, 'etc', which has the file module.xml inside of it. In the Magentoexplorer folder I have registration.php. The codes are copied from the example in the link I provided, see them at the end of the post.

  3. In windows CMD (I have Magento 2.1.2 installed over WAMP server), I do php magento setup:upgrade. It seems that it's working. I get the message 'please re-run Magento compile command', though. In a forum I read that this may be not necessary in developer mode. But I tried to do it anyway, just in case. I got the message 'Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in C:\wamp64\www\magento\vendor\zendframework\zend-code\src\Scanner\FileScanner.php on line 36'. I tried to go to php.ini and change the memory_limit to 1G. However, the error kept persisting.

  4. In the tutorials they advice to put code in app/code. In the version I downloaded I don't have this folder; for what I understood, my code is instead in the vendor/magento folder. I tried to put my module in first one folder, then in the other (I created app/code folder).

  5. I modified the magento config.php file adding a line at the end with 'Magentoexplorer_Helloworld' => 1'.

  6. When I tried to list the modules (php magento module:status), it didn't appear. I also tried 'php magento module:enable Magentoexplorer_Helloworld', but I got the error Unknown module(s): 'Magentoexplorer_Helloworld', which disappeared after modifying the config.php file, but then I couldn't see the admin page, nor the module.

  7. I am trying to understand what the composer does and how to use it, but in the tutorials they don't put it as a requisite for the module to be shown.

Is the composer necessary for the module to appear and work? I am new to php and Magento, and I am trying to learn by myself and searched everywhere but I still cannot figure out what is happening. Do you see any errors in what I have been trying? Am I missing something?

Code:

registration.php:

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Magentoexplorer_Helloworld',
    __DIR__
);

module.xml

<?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="Magentoexplorer_Helloworld" setup_version="1.0.0" / >
</config>

Any help or comment will be much appreciated.

Xavier

Était-ce utile?

La solution

you file path must be

app/code/Magentoexplorer/Helloworld/composer.json

{
    "name": "magentoexplorer/helloworld",
    "description": "my module",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/module-catalog": "101.0.*",
        "magento/module-config": "100.0.*",
        "magento/module-store": "100.0.*",
        "magento/module-customer": "100.1.*",
        "magento/module-backend": "100.0.*",
        "magento/framework": "100.0.*"
    },
    "type": "magento2-module",
    "version": "1.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Magentoexplorer\\Helloworld\\": ""
        }
    }
}

app/code/Magentoexplorer/Helloworld/registration.php

<?php 
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Magentoexplorer_Helloworld',
    __DIR__
);

now run the cmd php bin/magento setup:upgrade

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top