I find that Magento2 core modules don't follow the same style, so I cannot take a reference from there (they're all different).

How should a folder be named:

PreviouslyBought or Previouslybought? (module name under your package name)

A php file should be:

PreviouslyBought.php or Previouslybought.php?

A phtml file should be:

PreviouslyBought.phtml or Previouslybought.phtml or previouslybought.phtml?

A javascript file should be:

PreviouslyBought.js or Previouslybought.js or previouslybought.js or previouslyBought.js?

A css file should be:

previously-bought.css or previously_bought.css?

2 Answers 2


TL:DR: The difference between M1 and M2 regarding the file names is that in M2 you can use upper and lowercase as you want in the file names as long as you name the class in the same way.
For templates and js is the same. Just make sure you call the file names exactly how you declared them.

Long version: In M1 this was a problem because of the aliases.
In M1 you had this in config:


and you instantiated a model using

                       |        |
                       |        |
alias defined ---------|    rest of the class name and path 
in config                   

And this was processed by transforming from the second part (after the /) _lower letter into Upper letter.
The rest of the letters remained untouched.
And the result is added as a suffix for the value in the <class> tag under the alias <alias>.

So alias/some_class_name became Namespace_Module_Model_Some_Class_Name and this class was instantiated.

To get and instance of a class named Namespace_Module_Model_SomeClass_Name you had to do it like this:


(notice the uppercase C).

In M2, the class names are used in their normal form without aliases.
So for example, if you declare in one of your classes as dependency an instance of Namespace\Module\Model\SomeClass\Name, when this is instantiated by the Object Manager it will look for the file that matches the class name without any lower or uppercase transformations.

As a recommendation (it's not mandatory) I would say to use lowercase and underscores in the file names for templates: previously_bought.phtml and previously_bought.js and camel case names for php files PreviouslyBought.php


Just take file name like, PrevioslyBought,

As per Magento 2.1 files and folder structure use like below: Most of the places below files names are used in magento application,

Php file Name like, PreviouslyBought.php All php file name use in CamelCase manner.

Pthml file name like, previously_bought.phtml All phtml file is used as lower letter with underscore for each separate words.

Js file name like, previously-bought.js. All js file is used as lowercase with dash for each word.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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