Basic Magento 2 extension skeleton

What is necessary to create a very basic Magento 2 extension skeleton? Not that much. If you’re don’t have a patience to read the whole article – here is a link to download.

If you do – let’s start from basics.

Hint: Turn on developer mode while you working on new extensions

Create module

In Magento 1 we have three code pool folders under app/code directory: core, community and local. It’s much simplified in Magento 2 – now all extensions located by their namespace in same directory: app/code.

So to begin with module setup we need to create necessary files and folders. And here is a structure:

Now, when we have module structure – let’s fill it with some code:

1. Add following to app/code/YourName/FooBar/registration.php:

2. And this to app/code/YourName/FooBar/etc/module.xml:

Yes, that’s it – bare minimum to register new Magento 2 extension.

Module setup

Now when we have all necessary module files and folders in place – let’s register and enable it.

Navigate to your magento root folder and run following commands in terminal:

This will enable your module, flush some cache and register it with the database.

Now go to Admin -> Stores -> Configuration -> Advanced -> Advanced in admin panel. You should be able to see your module available there.

That’s all – in my next articles I will extend this basic skeleton and add a controllers, blocks, etc.


Rating:

Rate this post

What do you think?

Required fields are marked *


*