简体   繁体   中英

Symfony2 services : list of examples?

I think I understand the concept of services, but I don't seem to be able to find practical, real-life examples of them, except, of course, for the mailer service. The mailer example is great, but it would really help me catch the whole thing if there were other ones. Can anyone provide me with a (short and simple) list of concrete cases where you should use a service ? I'm not asking for code here...

All business logic must be in service. According slide number 46 in How Kris Writes Symfony Apps . Thin model, thin controller, fat service layer.

You should think a Service like not a real "service" ( as the mailer ) but you have thinking about at the dependency Injection design pattern. So if you have an action named 'enrolledStudentAction()' your controller method should be thin and you have to make "the logic" inside a class named StudentManager. The studentManager do the logic in order to find the enrolled users and return the result to the controller. The controller call the method getEntolledStudent by the service container. Decoupling!

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