PHP MVC folder structure

Asked

Viewed 1,427 times

0

I am creating a MVC project in PHP and I was wondering how to create the structure of the folders correctly. I made a folder template based on the projects I found on Github but I don’t know if it’s the best way.

inserir a descrição da imagem aqui

  • Only in this image already lack pattern in my view, the folder names one so lower case, image folder outside the set css, js good really the organization of folders is important but, also the nomenclature.

  • sure I’ll pay attention to it, but how much the folder structure can help me ?

  • I think it might be App -> Controller and App -> Model and App -> View and App -> Public and App -> Vendor to start.

  • 2

    If I’m not mistaken, the briefcase vendor, created by Composer, the name is strictly lowercase.

  • Make sure you use the nomenclatures correctly. Regardless of the name you put, you must follow upper and lower case when including the files in these folders. A vendor should be lowercase, as Composer himself already creates. Remember: the Windows file system is case-insensitive. Linux does not!

  • Could someone pass me a project link with a similar structure that is correct ?

  • 1

    There is no correct structure. You structure the way you meet your needs, not those of others. Comparing it to one-off projects won’t do you any good.

Show 2 more comments

1 answer

6

Mano basically, for a project structure that follows the MVC Standard, you could have basically 3 directories: Model, View and Controller. Each folder must contain the responsibility files to which it refers... It is very common for these 3 directories to be inside a parent directory called src(source) which is at the root of the project. At the root there may be other directories like Public, which will contain the files that will be exposed to the Web, there may also be some configuration files like bootstrap.php or composer.json (if use and recommend to use).

Basically it could look like this:

projeto-php
├── bootstrap.php
├── composer.json
├── config
├── public
│   └── index.php
├── src
│   ├── Controller
│   ├── Model
│   ├── Services
│   └── View
└── vendor

Browser other questions tagged

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