How to name folders in PHP’s MVC structure

Asked

Viewed 531 times

0

How should the folders be named in MVC? In upper or lower case letters? And the files? How should they be named? The controllers, must have 'Controller' at the end or just the name? And the models appointment? Must be singular and contain 'Model' at the end of the file name or only its name?

I found some information in PHP-FIG regarding file naming, but not in the MVC structure

  • There is no rule that dictates this, you can implement it in the way that best suits your needs. MVC is a concept (an idea/philosophy), it is not concrete, so it does not dictate anything about how the implementation will be.

  • I always use the Laravel pattern because I feel more comfortable. Each one uses what you think best.

2 answers

3

MVC (Model-View-Controller) is a standard software architecture where it does not become mandatory to directly determine the name of directories and files, however you can follow the concept used by some successful Frameworks that follow this pattern, for example, the directory structure of Laravel 4.2 is all lowercase and plural:

controllers, models, views

The classes created in controllers follow the following pattern: Named daclassecontroller.php; Already the classes created in models follow the pattern: Name.php; And the classes created in views follow the pattern: php name. or name.blade.php (if you use Blade for templates).

0

It does not have a defined rule, but the pattern used by most is:

Models: where are the variables and methods of data manipulation, e.g., a client class that contains name, CPF... as attributes, and manipulation methods in the database, since you can also extract these manipulation methods to a third class, leaving only attributes and other types of methods in the model.

Controllers: manipulates screens, displays messages, redirects to other pages... basically that’s it.

Views: are your Html pages.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.