O
O
Outsider V.2017-07-06 09:41:31
symfony
Outsider V., 2017-07-06 09:41:31

Bundle system in Symfony: where to write your code?

I am studying this framework (I want to write a simple organizer) and I still don’t understand: where should I write my code, my controllers, services - in src/AppBundle or in src/asoft/OrganizerBundle (I created this bundle according to the instructions, maybe in vain?). It’s just that the same Doctrine requires you to specify a bundle of type mycompanny:MyBundle when creating an Entity, but I don’t understand what AppBundle is. Can you do everything right in it, without creating anything additional?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
GTRxShock, 2017-07-06
@GTRxShock

if the application is simple, src/AppBundle is enough, if it is more complicated, then you can (and often need to) split into bundles and group as you like, ala src/OrganizerBundle, src/AdminBundle, etc.
ps if you expect a lot of bundles, you can add another nesting level
src/Organizer /CoreBundle, src/Organizer/AdminBundle and so on,
read best practices about bundles for a simple application
symfony.com/doc/current/best_practices/creating-th...
for complex ones, these recommendations are not applicable.
mycompanny:MyBundle is a standard stub from version 2, if you just leave the name of the bundle, I think nothing will break

O
OnYourLips, 2017-07-06
@OnYourLips

Can you do everything right in it, without creating anything additional?
Exactly. Best Practice now - 1 bundle per application.
https://symfony.com/doc/current/best_practices/bus...
And only the code that you use in several projects can be separated into a separate bundle (and a separate project at the same time, then connect via composer)
Don't use this notation. Use MyClass::class.

K
Konstantin Malyarov, 2017-07-06
@Konstantin18ko

Do the routing first.
There is routing of bundles (the folder where the symfony setting is), there is routing in the bundle (the bundle that you created).
Then you create entities in your bundle.
Then go to the controllers folder.
And only then go to the views folder where you write a visual representation.

D
Dmitry Belyaev, 2017-07-06
@Goblion

AppBundle is a basic bundle created with the Symfony installation.
You can use it instead of OrganizerBundle or just delete it.
The choice is yours.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question