M
M
maerio2019-10-01 14:34:42
PHP
maerio, 2019-10-01 14:34:42

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              # Классы приложения. Вопрос связан с этим моментом

In the Lib folder, I have all sorts of classes needed for the application, whether it's a class for working with the database, or for working with I \ O. Question: can I call it libs, did I name the folder correctly? It's clear that I can at least name a folder after my cat, but how will it be .. Correct? More expressive? If I called her Classes, it would be.. Hmm. Strange (for namespace) App\Classes\DatabaseManager

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
ThunderCat, 2019-10-01
@maerio

but how will it be .. Correct? More expressive? If I called her Classes, it would be.. Hmm. Strange (for namespace) App\Classes\DatabaseManager
It’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
...

O
Orbb, 2019-10-01
@humiliation

https://www.php-fig.org/
choose whichever is comfortable for you, but stick to the PSR.

O
Oleg, 2019-10-01
@402d

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

N
Northern Lights, 2019-10-01
@php666

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 question

Ask a Question

731 491 924 answers to any question