21

I just installed the first official release of Magento 2. I was surprised to find that the app/code folder was gone

app/code

This was for both the version downloaded from the website and the version installed via composer. Also, when I tried to manually create the app/code folder, and then do a php bin/magento module:enable Pulsestorm_MyModule to enable a sample module, I got the following error

 Unknown module(s): 'Pulsestorm_MyModule'

Where are third party modules supposed to live? If the answer is "a source repository and installed via composer", how does a module developer need to structure their modules to live in a Magento 2 repository?

18

Preferably 3PLs will live in the vendor directory along with everything else. However… :) We all know there is typically custom code written for almost every custom site-build out there, and this IMO belongs in app/code/ still. Yes, you can still run a module from app/code.

All modules, regardless of location, should have a composer.json and a registration.php file which are used to get the module into the system. You also need the etc/modules.xml file. This is, technically, all it takes to register a module:

$ tree app/code/Alger/
app/code/Alger/
└── Skeleton
    ├── composer.json
    ├── etc
    │   └── module.xml
    └── registration.php

2 directories, 3 files

To get the module up and running, you need to run setup:upgrade and then cache:flush for the system to both recognize and load your new component:

$ bin/magento module:enable Foo_Bar
$ bin/magento setup:upgrade -q && bin/magento cache:flush -q

Update: Two methods to install module from public GitHub repo: https://gist.github.com/davidalger/77761f13d9752b117f35

  • I haven't needed to module:enable unless I previously disabled it. Is there a parameter you can set to install the extension disabled? – Eirik Nov 20 '15 at 22:50
  • @Eirik If you're installing from repo via composer, it's done by composer. If you simply place these files there, that's when you need to enable it. At least I'm pretty sure that's what I found right after the GA as I was polishing up slides for a talk here at #phpworld :) – davidalger Nov 20 '15 at 22:53
  • thanks much haven't pushed to repo yet as I was working locally. Great information. – Eirik Nov 20 '15 at 22:54
6

Alan, they still go in app/code. Make sure you have a registration.php in the modulename folder containing the following:

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

Then run:

php bin/magento setup:upgrade

Just tested on fresh Magento 2 CE release and works properly.

  • Thank you @Eirik, that was indeed it. It wasn't clear if registration.php was something that slipped in that shouldn't have, or something that would make the final release. Pretty clear now :) – Alan Storm Nov 20 '15 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.