简体   繁体   中英

How to structure correctly a Symfony2 controller - deal with huge classes

I have an existing PHP project that I have to move on Symfony. I am working with symfony for 6 month and found it very nice to use.

Hovewer, I have a question:

In the old code, I have some big classes of about 6000 each :| Now, In the new project, I have My controller where everything should be done (including 2 or 3 classes of 6000 lines).

What is the best practcice with symfony , creating another bundle per huge class and call the functions of 2 or 3 bundles in the controller, or something else?

Read up on Symfony more and the answers may just fall into place, especially Services http://symfony.com/doc/current/book/service_container.html

EDIT

Look at the code and divide it up logically. I have no idea what the controller does, but it could well be valid as one class - but that is unlikely. Look at the class and make decisions about how best to split it up.

Do this as a diagram or on paper first! Doing it in code first takes much much longer and is harder to fix when you inevitably make a mistake the first time around.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM