M
M
matperez2015-08-27 10:53:26
PHP
matperez, 2015-08-27 10:53:26

How to structure projects in Yii2?

Hello! How do you structure files in Yii projects?
I have a not very large project in which the components folder has already grown to 50 files and everything says that there will be even more of them. For example, there are things like Model, ModelQuery, ModelRepository, ModelFactory, ModelRepositoryInterface and ModelFactoryInterface. Where is all this farming laid out? Now my Model is in the models folder, everything else is in components. And there are a bunch of adapters for third-party libraries and services that work on their own.
Part of the functionality can sometimes be packaged into modules if it is responsible for a specific aspect of the site (for example, the order process and all related components, helpers, forms, widgets, controllers and assets).
A part can be separated into separate libraries and connected later via composer. But still there is a lot of common code that just falls into the components folder.
Have you encountered a similar problem? Do you think this is a problem? How do you decide?
upd// in general, apart from modules and libraries, files in a project can be arranged in just two categories: by features and by types. yii2 developers themselves divide their framework by features (web, console, base, mail), but the base application is organized by types (models, controllers, components). hence the cant: it seems that a lot of features have been implemented, there are also a lot of object types, but they do not pull separately for separate modules or composer packages. for myself, I decided to divide the folder with components by features and scatter all the variety of classes there. And leave the project root as standard with separation by type.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaliy Orlov, 2015-08-27
@matperez

I would group by type, within type by scope
- app/models/user
- app/models/order
- app/models/...
- app/factories
- app/repositories
- app/...
- runtime
- modules
- vendors

V
Vit, 2015-08-27
@fornit1917

But who doesn't let you group the components folder (and others) into subfolders and namespaces?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question