Answer the question
In order to leave comments, you need to log in
How to organize the structure of a self-written PHP project?
I'm starting to write a self-written project from scratch, without any frameworks, but with composer, using PSR-4.
So far I have this structure:
├── config # Для всех конфигов
├── public # Для публичного контента
│ └── index.php # Точка входа
├── src # "App\" для автолоуда, непосредственно приложение
│ ├─ Lib # Классы приложения. Вопрос связан с этим моментом
Answer the question
In order to leave comments, you need to log in
but how will it be .. Correct? More expressive? If I called her Classes, it would be.. Hmm. Strange (for namespace) App\Classes\DatabaseManagerIt’s more correct to divide it into Model / Controller / View, because this is the most logical way from the point of view of the PHP life cycle (and not only PHP). Everything that works with entities - models, displays in html / xml / json - views, controllers ... well - controllers of their own. If you have things of a basic nature - DBs and others - just lib (since they are essentially "third-party" applications / libraries that practically do not change during development).
├── config # Для всех конфигов
├── public # Для публичного контента
│ └── index.php # Точка входа
├── src # "App\" для автолоуда, непосредственно приложение
│ ├─ Controllers
│ │ ├─SomeController.php
...
│ ├─ Models
│ │ ├─User.php
...
│ ├─ Views
│ │ ├─index
│ │ │ ├─index.php
...
│ ├─ Lib
│ │ ├─DatabaseManager.php
...
https://www.php-fig.org/
choose whichever is comfortable for you, but stick to the PSR.
Do not mix in one pile, something that may be useful in another instance of the project and required only for a specific
one - app
.|- config
.|- controler
.|- models
.|- view
-src - here are your libs
- vendors - others
- public - web root
no lib folders
open any framework - everything is built on namespace there.
everything has already been said regarding the MBC, but I strongly advise you not to put everything in the Model / Controller / View folders, but to create MODULARITY, when each module is in its own directory (in its own namespace).
Look how it's done in my framework. And here is the link skeleton . Pay attention to the Module directory in both the frame and the skeleton. There are modules that, like bricks, can theoretically be transferred from one project to another.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question