Some articles encourage to create custom extensions in app/code
and some other encourage to create them under vendor
. Are both these two methods fine?
What if I want to override a module in vendor
? Do I need to write my custom module also inside vendor
folder or app/code
?
Do they act as codepools as in Magento 1.x?
Please anyone clarify the purpose of each directories.
Best Answer
You can look at the folders
app/code
andvendor
as the codepools in M1, but they are not really codepools.There is no "codepool" concept in M1.
vendor
folder is for modules you download via composer. You should not write code in that folder.app/code
is your playground. Add your own extensions here.If you need to rewrite/extend something in the
vendor
folder you can do it in theapp/code
folder. Just make sure you specify the soft dependency in themodule.xml
of your module, in the same way you did it in M1 inapp/etc/modules/Namespace_Module.xml
file.The only difference is that in m2 they are not actually dependencies. They are sequences.
This way your module will be loaded after the one from the
vendor
folder