Answer the question
In order to leave comments, you need to log in
How to understand the symfony2 philosophy?
I started digging from the side of symfony2, read some Russian docks and immediately had questions about the structure.
Let's say comparing symfony2 with Yii2, can we say that the bundle is a regular module?
Then I did not quite understand where to write the main application code (let's say where in the model symphony?). That is, there is no concept of a model in symphony, but (these are not models) should be located in the Entity folder of my bundle?
And the last question, is there such a thing as widgets in symfony2 (like in Yii2) ?
Answer the question
In order to leave comments, you need to log in
Bundles are self-sufficient modules that encapsulate some services and other stuff. In fact, these are extensions for DependencyInjection, if very roughly.
Models are those same Entities roughly speaking. In general, there is such a thing as a domain model. This is just a data structure, the entities that the business logic operates on. The latter must be encapsulated in services (any UserManager, PostManager, etc.). In Yii, the models are mixed with the service layer and that's why you get confused.
As for the code... it's a common approach to have your own AppBundle and screw everything in it. There is also a recommended approach - do not use bundles at all. That is.... bundles should be self-sufficient and their main purpose is to reuse logic between projects. You won’t be able to reuse the business logic of the application, so it’s recommended to just write code and register it in app/Resources/config/services.yml or something like that, it’s up to you how to decide. The benefit is that you don't bother with all this garbage with bundles and you have fewer questions about the structure. And if you want to put something into the bundle - for example, authorization services that can really be reused, then no one will stop you from doing this. As a result, you will have a project structure that looks something like this:
| - app
| - var
| - src
| - Controller
| - Entity
| - Bundle/
| - MyAuthBundle/
| - web
<div id="sidebar">
{{ render(controller('AcmeArticleBundle:Article:recentArticles', {
'max': 3
})) }}
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question