Symfony2 and be dry in controllers

I am developing a small CMS for my company using Symfony2. I really like this framework. I like class classes and their reuse (which is all about forms after all).

But (yes, there is a "but"). I feel like doing the same thing, copy and paste all the controllers . The coding we hate. When all the business logic has moved to Services , as well as forms, events, actions in action in Doctrine, all my controllers do the same:

  • Get repository $this->get('mycompany.repository.entity')
  • Dynamically create a form (logic inside the form class itself)
  • Validate form, return view or save object
  • etc.

I mean, controller actions are all the same , just a few characters.

How can there be DRY with Symfony2 in my controllers? Maybe the dispatcher as a service (a concept that I discovered just a few days ago) can help?

EDIT : related question (to the first idea proposed by Boo): Symfony2 how to redirect to an action without a hard drive routing name?

+5
source share
1 answer

There are many ways to get a drier code base:

  • BaseController. , (), . , , .
  • BaseService, , (, ),
  • , , .

, .

1 , 3 . - , , ( , ). 1 OO, . , BaseController!

+2

All Articles